subprocess with shared environment?

R

rowen

I'd like to replace some shell scripts with Python, but one step of
the script modifies my environment in a way that the subsequent steps
require.

A simple translation to a few lines of subprocess.call(...) fails
because the first call modifies the environment, but the other lines
don't see it.

Is there a straightforward way to do this (without having to resort
to writing some of it as a shell script)?

-- Russell
 
G

Gabriel Genellina

I'd like to replace some shell scripts with Python, but one step of
the script modifies my environment in a way that the subsequent steps
require.

A simple translation to a few lines of subprocess.call(...) fails
because the first call modifies the environment, but the other lines
don't see it.

Is there a straightforward way to do this (without having to resort
to writing some of it as a shell script)?

The first subprocess modifies *its* environment and dies - the
modification is not seen by the caller process. I don't know of any way to
modify parent's environment.
You might "echo" the desired changes in the first subprocess, read them
from the parent process and modify the environment that will be passed to
later subprocesses. Perhaps someone else provides a more straightforward
solution...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top