why Popen can't exec python cmd?
Question: I want to exec command using Popen, see my code below:

    
    
    import subprocess
    p = subprocess.Popen('/usr/bin/python a.py')
    p2 = subprocess.Popen('ls', stdout = subprocess.PIPE)
    print p2.stdout.readlines()
    

while I exec this script, I get the error below:

    
    
    File "demo.py", line 4, in <module>
      p0 = subprocess.Popen('/usr/bin/python a.py')
    File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
     errread, errwrite)
    File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
      raise child_exception
    OSError: [Errno 2] No such file or directory
    

What's the problem? Another question is what if a.py is a 'while-True-loop'
can p2 return?

Thanks!


Answer: Check your python and your "a.py" script path and make sure they exist!

After that try this :

    
    
    import subprocess
    p = subprocess.Popen(["/usr/bin/python" , "a.py"], stdout=subprocess.PIPE)
    out, err = p.communicate()
    

good luck!

