subhra subhra - 1 year ago 104
Python Question

Getting error while doing subprocess call using Python and Django

I am getting some error while running the

.sh
script using Python and Django. The errors are given below.

Traceback (most recent call last):
File "cell.py", line 3, in <module>
subprocess.call(shlex.split('./test.sh param1 param2'))
File "/usr/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied


I am explaining my code below.


cell.py:


import subprocess
import shlex
param1='Reactor1'
param2='Running'
subprocess.call(shlex.split('bash test.sh',param1,param2))



test.sh:


#!/bin/sh
echo $1
echo $2
exit 0


While I was running the file I am getting the above error. Please help me to resolve this error.

Answer Source

Replace your

subprocess.call(shlex.split('bash test.sh',param1,param2))

To

subprocess.call(shlex.split('bash test1.sh %s %s'%(param1,param2)))

or

subprocess.call(['bash', 'test1.sh', param1, param2])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download