buntuser
buntuser

Reputation: 99

Window does not close when Python script on Windows is finished, until launched program exits

The follwing python script works fine, exept that the shell window remains open.

file = open("C:\\Documents and Settings\\User1\\Desktop\\BPanel\BadePanel\\SteelUsage.bsu", "a+")
input = raw_input("Please enter project name:")
input = input.upper ()
for line in file.readlines():
        if input in line:
            print "Project name already exists, executing BadePanel"
            import time
            time.sleep(4)
            import subprocess
            subprocess.call(['C:\\Documents and Settings\\User1\\Desktop\\BPanel\BadePanel\\BadePanel.exe'])
            exit(subprocess)
file.write (input+"\n")
print "Project name written to file, executing BadePanel"
import time
time.sleep(4)
import subprocess
subprocess.call(['C:\\Documents and Settings\\User1\\Desktop\\BPanel\BadePanel\\BadePanel.exe'])
exit(subprocess)
file.close()

The shell window terminates ony after i close the exeuted progrm (BadePanel.exe)
I would like the script to display the printed text in the shell window, wait 4 secs, execute the program, and then exit.
Thanks

Upvotes: 0

Views: 272

Answers (1)

Robᵩ
Robᵩ

Reputation: 168626

From the doc:

subprocess.call()

Run the command described by args. Wait for command to complete, then return the returncode attribute.

So the .call() function only ever returns after BadePanael.exe finishes.

Instead, try:

print "Project name written to file, executing BadePanel"
time.sleep(4)
subprocess.Popen(['C:\\Documents and Settings\\User1\\Desktop\\BPanel\BadePanel\\BadePanel.exe'])
sys.exit(0)

Upvotes: 1

Related Questions