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.