Tôi là một người mới bắt đầu bằng Python, và tôi đã cố gắng để gọi một ứng dụng dòng lệnh, nhưng nó không thành công:Calling ứng dụng từ subprocess.call với đối số
>>> import subprocess as s
>>> s.call("gpio -g read 17")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/subprocess.py", line 470, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Nhưng sau đó nếu tôi thêm shell=True
nó tất cả bắt đầu hoạt động. Ai đó có thể giải thích lý do tại sao?
>>> import subprocess as s
>>> s.call("gpio -g read 17", shell=True)
>>> 0
Tại sao thêm "shell = True" làm cho nó hoạt động? –
Và với 'shell = True', lệnh này được gửi đến một shell, sau đó tách đối số tách. – mgilson
@MarkIngram - dường như chúng tôi đã nhận xét cùng một lúc. – mgilson