简体   繁体   中英

OSError: [errno2] no such file or directory

I am trying to get the signal from pir sensor to transfer it to web service. When I run this code

if Current_State==1 and Previous_State==0:
  # PIR is triggered
    output =  subprocess.check_output(["Current_State==1 and enter code herePrevious_State==0","18"]);
     print "  Motion detected!"
     # Tell the Pi to run our speech script and speak the words
     # motion dtected! - anything after the .sh will be read out.
    enter code here` matches = re.search("Current_State==1 and Previous_State==0", output)
     move = int(matches.group(1))
     resultm = client.service.retrieveMove(move)

I got this error

**Traceback (most recent call last):
  File "pir_5.py", line 48, in <module>
    output =  subprocess.check_output(["Current_State==1 and Previous_State==0", "18"]);
  File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory****

subprocess.checkoutput() expects to be given a command to run so that it can capture the output, as per the canonical example in the Python documentation:

subprocess.check_output(["echo", "Hello World!"])

which gives you, as expected, the string 'Hello World!\\n' .

The command you're giving it is:

["Current_State==1 and enter code herePrevious_State==0","18"]

which is very unlikely to be valid.

You need to actually figure out what you want to do (it's unclear from the question) then construct the command based on that. For example, if you want to log that somehow (with a program called logMe ), you would do:

output = subprocess.check_output(["logMe","CurrState=1 and PrevState=0","18"]);

You need to give subprocess.check_output a shell command in the first argument of the list. Then the 2nd, 3rd, whatever elements are the 1st, 2nd, whatever arguments to the shell command.

Current_State==1 and enter code herePrevious_State==0 is not a shell command.

/bin/true is.

pwd is.

echo foo is.

ls /tmp is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM