bash - subprocess popen Python -


i executing shell script starting process background option &. shell script called python script hangs.

shell script:

test -f filename -d & 

python file

cmd =["shellscript","restart"] proc = subprocess.popen(cmd, stdout=subprocess.pipe,                           stderr=subprocess.pipe, stdin=subprocess.pipe, **kwargs) pid = proc.pid out, err = proc.communicate() returncode = proc.poll() 

python file hangs , won't return out of python process. python process automated one.

the call proc.communicate() block until pipes used stderr , stdout closed. if shell script spawns child process inherits pipes, exit after process has closed writing ends of pipes or exited.

to solve can either

  • redirect output of started subprocess /dev/null or logfile in shell script, e.g.:
    subprocess_to_start >/dev/null 2>&1 &
  • use subprocess.devnull or open file object stderr , stdout in python script , drop communicate() call if don't need output of "shellscript" in python

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -