Call program from subprocess.Popen in python: `OSError: .. No such file or directory`
Question: I run the following command from my bash script:

    
    
    myProgram --name test1 --index 0
    

But now I want to run it from within a python script so I have tried the
following:

    
    
    #!/usr/bin/python
    from threading import Thread
    import time
    import subprocess
    
    print "hello Python"
    
    subprocess.Popen("myProgram --name test1 --index 0")
    

But I get the error:

    
    
    hello Python
    Traceback (most recent call last):
    File "./myPythonProgram.py", line 8, in <module>
    subprocess.Popen("myProgram --name test1 --index 0")
    File "/usr/lib64/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)
    File "/usr/lib64/python2.6/subprocess.py", line 1141, in _execute_child
    raise child_exception
    OSError: [Errno 2] No such file or directory
    

Is the correct way to call this??


Answer: You need to pass the command as a list:

    
    
    subprocess.Popen("myProgram --name test1 --index 0".split())
    

