I need to call a batch script from Python that sets environment variables and then use those environment variables to complete the execution of other programs. I am in a windows environment running python.
I cannot call Popen("setupEnv.bat")
and then call Popen("command args")
because the env variables are lost after the batch script is finished. Since this failed, I am trying to open a cmd prompt manually and intercept the output of each command separately, but I'm having trouble with this:
proc = subprocess.Popen("cmd.exe",stdin=subprocess.PIPE,stdout=subprocess.PIPE,
stderr=subprocess.STD OUT,shell=True)
stdin.write("setupEnv.bat")
stdin.write("command args")
I need to intercept the output for these seperately. Is there some mechanism to pause the childprocess or wait for its output. proc.communicate()
and proc.wait()
both wait for the child process to terminate. I need to send two separate inputs to a process and log the response for each.
Thanks