2014-03-30 18 views
1

我目前正在爲我的Raspberry Pi組合一個溫度傳感器,並遇到此問題。爲了運行代碼中指定的驅動程序,我必須運行它是一個shell命令。我很難搞清楚爲什麼我的語法不正確。調用Raspberry Pi溫度傳感器,調用驅動程序作爲bash腳本時的語法無效

代碼:

def read_dht22(PiPin): 
     output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)]) 

錯誤:

sudo python scr6.py 
    File "scr6.py", line 31 
    output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver', '2302', str(PiPin)]) 
             ^
SyntaxError: invalid syntax 

錯誤之前,加入shell =真

sudo python scr5.py 
Traceback (most recent call last): 
    File "scr5.py", line 46, in <module> 
    temp_c, temp_f = read_dht22(4) 
    File "scr5.py", line 31, in read_dht22 
    output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver", "2302", str(PiPin)]) 
    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 13] Permission denied 

回答

0

這應該修復你的語法錯誤:

def read_dht22(PiPin): 
    output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)], shell=True) 
相關問題