1

I am trying:

import subprocess
subprocess.call(["file.sh"])

But I keep getting:

Traceback (most recent call last):
  File "project.py", line 85, in <module>
    subprocess.call(["file.sh"])
  File "/usr/local/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/local/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/local/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

However when I try and run the script from the shell bash file.sh it works. So I'm confused as to why it doesn't work?

I am not committed to using subprocess so if there are other options please let me know.

2
  • Does file.sh (as opposed to bash file.sh) work from the command line? No? Why do you expect subprocess.call(["file.sh"]) to work then? Commented Nov 28, 2015 at 12:20
  • I just tried adding (["bash file.sh"]) and exactly the same result. Commented Nov 28, 2015 at 12:28

1 Answer 1

3

The call function of the subprocess package runs the command specified in arg as a list of strings (to simplify).

To call your file you have put in your script:

import subprocess
subprocess.call(["sh", "file.sh"])
Sign up to request clarification or add additional context in comments.

1 Comment

Is the script file.sh in the same directory as your python script ? Else you must replace "file.sh" with the path to the file. No prob.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.