python - File not found error when launching a subprocess -
i need run command date | grep -o -w '"+tz+"'' | wc -w using python on localhost. using subprocess module same , using check_output method need capture output same.
however throwing me error :
traceback (most recent phone call last): file "test.py", line 47, in <module> check_timezone() file "test.py", line 40, in check_timezone count = subprocess.check_output(command) file "/usr/lib/python2.7/subprocess.py", line 537, in check_output process = popen(stdout=pipe, *popenargs, **kwargs) file "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) file "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child raise child_exception- oserror: [errno 2] no such file or directory please help going wrong. i'm new python
you have add together shell=true execute shell command. check_output trying find executable called: date | grep -o -w '"+tz+"'' | wc -w , cannot find it. (no thought why removed essential info error message).
see difference between:
>>> subprocess.check_output('date | grep 1') traceback (most recent phone call last): file "<stdin>", line 1, in <module> file "/usr/lib/python3.4/subprocess.py", line 603, in check_output popen(*popenargs, stdout=pipe, **kwargs) process: file "/usr/lib/python3.4/subprocess.py", line 848, in __init__ restore_signals, start_new_session) file "/usr/lib/python3.4/subprocess.py", line 1446, in _execute_child raise child_exception_type(errno_num, err_msg) filenotfounderror: [errno 2] no such file or directory: 'date | grep 1' and:
>>> subprocess.check_output('date | grep 1', shell=true) b'gio 19 giu 2014, 14.15.35, cest\n' read documentation frequently used arguments more info shell argument , how changes interpretation of other arguments.
python shell subprocess
No comments:
Post a Comment