In the script I've attached below I'm attempting a pretty simple process using Python. Sequential execution of native Windows commands as well as calling executables from Freeware, portable programs. The subprocess.call() function isn't operating as expected though.
Behavior I'm experiencing:
~ The ONE variable gets called and then stops/waits, like I expect it to, but when I exit out of ONE (taskmgr) it starts TWO and THREE simultaneously and then waits.
~ When I exit THREE it calls the two portable programs, FOUR and FIVE, simultaneously and waits.
~ It then starts SIX and waits.
~ Finally it executes the rest of the commands simultaneously without pausing.
Any explanations for the cause of this behavior? And/or suggested work arounds for accomplishing the same results?
import subprocess
def AutoCommands():
ONE = 'taskmgr /0 /startup'
TWO = 'taskschd.msc'
THREE = 'services.msc'
FOUR = '"%CD%/FolderDirectory/PortableProgram" -custom -flags'
FIVE = '"%CD%/FolderDirectory/PortableProgram2" -more -flags'
SIX = '"%CD%/FolderDirectory/PortableProgram3" -more -flags'
SEVEN = '"appwiz.cpl"'
EIGHT = 'wuapp'
autocommands = [ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT]
for command in autocommands:
subprocess.call(command, shell=True)
AutoCommands()
EDIT: I expect/want each command to be executed but not moving onto the next command until the current one has been cancelled/killed. Similar to using start /wait program.exe && program2.exe, etc... I've written the above script in .bat and it runs as you would expect, waiting in between commands. However if I try executing that .bat using os.system() or subprocess.Popen() it exhibits the same behavior. If I try directly using os.system("start /wait program.exe && start /wait program2.exe") it's exhibits the same behavior.
I've also tried the suggestion here using subprocess.Popen (not what I want to use) but couldn't get that to work at all.
subprocess.check_call("\n".join(autocommands), shell=True)(if it fails try"; "or" & "instead of"\n")..call()function. I expect it to execute a command and wait for that command to be cancelled/exited. Similar to usingstart /wait commandhereor using&&, etc... I even tried making a.batfile with the above script example and it worked fine (waiting in between commands) however even when I open the.batusingos.system(./batchfile.bat)orsubprocess.Popen(./batchfile.bat)it has the same initial behavior mentioned in the question.check_call()). 2. "puts the specified character in between each letter" -- no, it won't.autocommandsis a list:" & ".join(["1st", "2nd"])->"1st & 2nd". My best guess is that your commands fail to start that is why you see them to return immediately that is why I've suggestedcheck_call()that raises an exception instead of ignoring the error silently.