How can I execute a shell command in a child process in Python? -
i need use multiprocessing module (rather subprocess, need use pipes) execute shell command new child process. @ moment i'm using:
p = subprocess.popen(subprocess_command, stdout=subprocess.pipe, stderr=subprocess.pipe, env=parent_env)   where subprocess_command shell command (it runs python script arguments) , parent_env current environment environmental variable (ld_preload) set differently. equivalent using multiprocessing module? child process (python script) needs able pipe parent.
this demonstrate how streaming output popen
file1.py
import time,os while true:     print "ok ?"+os.environ["ld_preload"]     time.sleep(1)   file2.py
import os os.environ["ld_preload"] = "5" p = subprocess.popen(subprocess_command, stdout=subprocess.pipe, stderr=subprocess.pipe, env=os.environ) p.start() line in iter(p.stdout.readline, b''):    print line    time.sleep(0.6)      
Comments
Post a Comment