Search code examples
pythondebianpopen

Popen giving error in python when trying to execute a script


Have having issues with Popen in python. Code in question:

from subprocess import Popen
Popen(["nohup", "/usr/local/bin/python2.7  /somescript.py"])

With following error:

 failed to run command `/usr/local/bin/python2.7  /somescript.py': No such file or directory

Thing is that when I run the same command in a terminal, it works and the file definitely exists.


Solution

  • You are missing 2 " and a , Popen takes a list of arguments. Try this:

    from subprocess import Popen
    Popen(["nohup", "/usr/local/bin/python2.7",  "/somescript.py"])