Reputation: 1
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-
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
what is the problem?
Upvotes: 0
Views: 1211
Reputation: 19375
what is the problem?
The OSError: [Errno 2] No such file or directory
refers to the subprocess command which is to be executed.
The program arguments must be passed individually in the sequence, so change
["sudo iwlist wlan0 scan"]
to
["sudo", "iwlist", "wlan0", "scan"]
Upvotes: 2
Reputation: 413
It looks like your code is using a file called "subprocess" located here: /usr/lib/python2.7/subprocess.py
But the file or directory isn't there. You can change the dir or put the file in the correct folder.
If it's an packaged. Did you install the package with pip or sth? Is it imported?
Upvotes: 0