Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

This may not be exactly what you're looking for
You could get the value of the var's then store them in a file. After that get the contents of the text file with the other program/language. Just do that :)


Hopefully that answered your question!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.