0

I have a series of scripts I am automating the calling of in python with subprocess.Popen. Basically, I call script A, then script B, then script C and so forth.

Script A sets a bunch of local shell variables, with commands such as set SOME_VARIABLE=SCRIPT_A, set PATH=%SCRIPT_A:/=\;%PATH%.

Script B and C then need to have the effects of this. In unix, you would call script A with "source script_a.sh". The effect lasts in the current command window. However, subprocess.Popen effectively launches a new window (kind of).

Apparently subprocess.Popen is not the command I want to do this. How would I do it?

edit I have tried parsing the file (which is all 'set' statements) and passing them as a dictionary to 'env' in subprocess.Popen, but it doesn't seem to have all worked..

1

3 Answers 3

0

You can use the env argument to Popen with a python dictionary containing the variables then you don't need to run the command that just sets variables.

Sign up to request clarification or add additional context in comments.

3 Comments

But this file changes every so often, and I don't want to update my python script with this every time. Wouldn't I have to do that?
Either that or you write an interpreter in Python for the minimal shell command subset that would allow you to set your variables.
No fun... Is there an alternative to subprocess.Popen that preserves the current command window?
0

if 'script A' get generated by another process, you will either need to change the other process so the output file is in a format that you can source (import) into your python script. or write a parser in python that can digest the vars out of 'Script A' setting them within your python script.

Comments

0

If all you want is to call a series of batch files using Python you could create a helper batch file which would call all these batch files like this

call scriptA;
call scriptB;
call scriptC;

and run this helper batch file using subprocess.Popen

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.