I'm learning how to run shell commands through the os module and the subprocess module. The following is my code.
from subprocess import call
call('/usr/lib/mailman/bin/find_member -w user_email')
import os
os.system('/usr/lib/mailman/bin/find_member -w user_email')
The second one works very well, while on the other hand, the first one does not work, and I got the following errors.
Traceback (most recent call last):
File "fabfile.py", line 6, in <module>
call('/usr/lib/mailman/bin/find_member -w user_email')
File "/usr/lib64/python2.6/subprocess.py", line 478, in call
p = Popen(*popenargs, **kwargs)
File "/usr/lib64/python2.6/subprocess.py", line 639, in __init__
errread, errwrite)
File "/usr/lib64/python2.6/subprocess.py", line 1228, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I thought those two methods have the same effect. Could you point to me what's the possible errors here? Many thanks.
call('/usr/lib/mailman/bin/find_member -w user_email', shell=True)or, better yet:call(['/usr/lib/mailman/bin/find_member', '-w', 'user_email']).