Python subprocess.check_output()
1 2 3 4 5 6 7 | mystring = subprocess.check_output(["sudo iwlist wlan0 scan"], universal_newlines=True) word = 'Devsign2G' print (mystring) print (word) if word in str(mystring): print ('success') |
- error message -P></
1 2 3 4 5 6 7 8 9 10 | Traceback (most recent call last): File"test.py", line 52, in mystring = subprocess.check_output(["sudo iwlist wlan0 scan"], universal_newlines=True) File"/usr/lib/python2.7/subprocess.py", line 212, in check_output process = Popen(stdout=PIPE, *popenargs, **kwargs) File"/usr/lib/python2.7/subprocess.py", line 390, in __init__ errread, errwrite) File"/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory |
什么是问题?P></
what is the problem?
程序参数必须按顺序单独传递,因此更改
1 | ["sudo iwlist wlan0 scan"] |
到
1 | ["sudo","iwlist","wlan0","scan"] |
您的代码似乎使用了一个名为"Subprocess"的文件,该文件位于以下位置:/usr/lib/python2.7/subprocess.py
但是文件或目录不在那里。您可以更改目录或将文件放在正确的文件夹中。
如果是包装的。你用PIP或其他东西安装了这个包吗?是进口的吗?