0
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?

2 Answers 2

2

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"]
Sign up to request clarification or add additional context in comments.

Comments

0

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?

2 Comments

This package is a built-in package in Python 2.7. I entered the command(sudo apt-get install subprocess) but the answer is "E: Invalid operation subprocess"
The package is already installed, as it can be seen from the traceback. The file subprocess is there, so this is not the source of the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.