unix - subprocess Popen in python with command that changes environment -


i'm trying run python script python using subprocess module , executing script sequentially. i'm trying in unix before launch python in new shell need execute command (ppack_gnu) sets environment python (and prints lines in console).

the thing when run command python subprocess process hangs , waits command finish whereas when in unix console jumps next line automatically.

examples below:

from unix:

[user1@1:~]$ ppack_gnu; echo 1 appear in prefix (shell=/opt/soft/cdtng/tools/ppack_gnu/3.2/bin/bash) 1 [user1@1:~]$  

from python:

processes.append(popen("ppack_gnu; echo 1", shell=true, stdin = subprocess.pipe)) 

this print entering gentoo prefix /opt/soft/cdtng/tools/ppack_gnu/3.2 - run 'bash -l' source full bash profiles in python console , hang...

popen() not hang: returns while ppack_gnu may still running in background.

the fact see shell prompt not mean command has returned:

⟫ echo $$ 9302 # current shell ⟫ bash ⟫ echo $$ 12131 # child shell ⟫ exit ⟫ echo $$ 9302 # current shell 

($$ -- pid of current shell)

even in bash, can't change environment variables of parent shell (without gdb or similar hacks) why source command exists.

stdin=pipe suggests want pass commands shell started ppack_gnu. perhaps need add process.stdin.flush() after corresponding process.stdin.write(b'command\n').


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -