mystring = subprocess.check_output(["sudo iwlist wlan0 scan"], universal_newlines=True)
word = 'Devsign2G'
print (mystring)
print (word)
if word in str(mystring):
print ('success')
-错误消息-
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
问题出在哪里?
看起来您的代码正在使用一个名为“子进程”的文件,该文件位于此处:/usr/lib/python2.7/子进程.py
但是文件或目录不在那里。您可以更改目录或将文件放在正确的文件夹中。
如果是打包的。你们是用pip还是sth装的包?是进口的吗?
问题出在哪里?
< code > OSError:[Errno 2]No this file or directory 指的是要执行的子进程命令。
程序参数必须在序列中单独传递,所以
["sudo iwlist wlan0 scan"]
到
["sudo", "iwlist", "wlan0", "scan"]