Reputation: 1293
I have a bash script which helps establish a local SimpleHTTPServer
.
python -m SimpleHTTPServer 8080
I have put this inside my project folder. While I am running the program by using:
subprocess.call('./setup.sh')
an error message comes out:
Traceback (most recent call last):
File "test.py", line 2, in <module>
subprocess.call('./setup.sh')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 709, in __init__
errread, errwrite)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1326, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
I retried this in terminal
localhost:Desktop XXXX$ sh setup.sh
Serving HTTP on 0.0.0.0 port 8080 ...
It is working fine. I remember there are a few times where the terminal has popped up a window ask me about the permission for python about something related to firewall and I allowed it. Can you help me?
Upvotes: 0
Views: 2059
Reputation: 3307
Give subprocess.Popen()
a try, with cwd param:
subprocess.Popen(['sh', './setup.sh'], cwd='/dir/contains/setup.sh/')
Upvotes: 1
Reputation: 1768
Run it exactly as you would on the shell, i.e., as sh ./setup.sh
:
subprocess.call('sh ./setup.sh', shell=True)
That should do the trick. Most likely, your setup.sh
is not set to executable or is missing the first #!
line that marks its interpreter.
EDIT:
Make sure to set shell=True
to execute it via the shell, if you pass it as a single string, or separate the parameters into a list, as you might with execve
:
subprocess.call(['sh', './setup.sh'])
Upvotes: 2