I have a functionality where I need to run a command inside a python script. From another answer, I figured call from subprocess module
is the safest way. But, I am unable to work through it. I am using python 2.7
This is a smaller version of what I am trying :
import subprocess
a = "echo hello"
subprocess.call([a])
It gives me the following error :
subprocess.call([a])
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 2] No such file or directory
I am unable to figure out why!