0
Python的回溯問題上運行我的代碼時,我得到這個錯誤:關於POPEN
Traceback (most recent call last):
File "./autoConnect.py", line 22, in <module>
call("wicd-cli -yn " + str(defNum) + " -c")
File "/usr/lib/python2.6/subprocess.py", line 470, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
問題是。我不知道它在告訴我什麼。我意識到下面的代碼是凌亂的。它需要清理。但由於某種原因,python在這裏跳了起來。有人能告訴我發生了什麼事嗎?再次
感謝, 德拉戈什
代碼:
#!/usr/bin/python
from subprocess import call, Popen, PIPE, STDOUT
import time
cmd = './checkOnline.sh'
while True:
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
if "0" in p.stdout.read():
print time.ctime() + ": Offline"
print "Attempting to reconnect..."
print "Determining network profile..."
cmdTwo = "wicd-cli -ySl | sed -n '2 p' | grep -i paws -c"
pTwo = Popen(cmdTwo, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
if "1" in pTwo.stdout.read():
print "Network profile is \"1\""
defNum = 1
else:
print "Network profile is \"2\""
defNum = 2
print "Connecting to network..."
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
while "0" in p.stdout.read():
call("wicd-cli -yn " + str(defNum) + " -c")
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
time.sleep(3)
if "0" in p.stdout.read():
print "Failed to connect. Trying again..."
print "Success, connected to network!"
else:
print time.ctime() + ": Online"
time.sleep(5)
'OSError:[Errno 2]沒有這樣的文件或目錄'讓我懷疑你是否指定了正確的文件路徑。 – Griffin
我覺得很愚蠢。 (「wicd-cli -yn」+ str(defNum)+「-c」) 是原始代碼。這不是正確的語法...命令第一,然後它是一個數組中的參數,如下所示: call([「ls」,「-l」]) – NiaKitty
@ dragos240:請將您的答案作爲答案並標記出來正確 – Sheena