OSError:[errno2]没有这样的文件或目录

use*_*694 0 python raspberry-pi

我试图从pir传感器获取信号,将其传输到Web服务.当我运行此代码时

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)
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

**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****
Run Code Online (Sandbox Code Playgroud)

pax*_*blo 6

subprocess.checkoutput()期望获得一个运行命令,以便它可以捕获输出,根据Python文档中的规范示例:

subprocess.check_output(["echo", "Hello World!"])
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,它为您提供了字符串'Hello World!\n'.

给它的命令是:

["Current_State==1 and enter code herePrevious_State==0","18"]
Run Code Online (Sandbox Code Playgroud)

这不太可能有效.

你需要实际弄清楚你想做什么(从问题中不清楚)然后根据它构建命令.例如,如果您想以某种方式记录(使用程序调用logMe),您将执行以下操作:

output = subprocess.check_output(["logMe","CurrState=1 and PrevState=0","18"]);
Run Code Online (Sandbox Code Playgroud)