2
我想用DevCon從python腳本重新啓動驅動程序。它的命令行工作用這個命令:從python執行DevCon CMD命令
devcon restart \"sd0007322081041363_kcanv\"
我嘗試這樣做:
os.system("devcon restart \"sd0007322081041363_kcanv\"")
與結果:
'devcon' is not recognized as an internal or external command
,我讀了使用os.system已過時,我需要使用subprocess.check_output所以我試試這個:
subprocess.check_output(['devcon', 'restart', '"sd0007322081041363_kcanv"'])
與結果:
WindowsError:[Error 2] The system cannot find the file specified
這:
subprocess.check_output('devcon restart "sd0007322081041363_kcanv"', shell=True)
與結果:
subprocess.CalledProcessError: Command 'devcon restart "sd0007322081041363_kcanv"' returned non-zero exit status 1
這:
subprocess.Popen("devcon restart \"sd0007322081041363_kcanv\"", shell=True, stdout=subprocess.PIPE).stdout.read()
結果:
'devcon' is not recognized as an internal or external command
這:
try:
subprocess.check_output('devcon disable "sd0007322081041363_kcanv" /f',shell=True,stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
與結果:
RuntimeError: command 'devcon disable "sd0007322081041363_kcanv" /f' return with errpr (cpde 1): 'devcon' is not recognized as an internal or external command, operable program or batch file
Devcon.exe的是在Windows/System32下,它是在系統路徑設置。
我知道這可能是重複的問題,但我已經嘗試了很多解決方案在stackoverflow但我不能解決這個問題。
嘗試指定的完整路徑和DEVCON的擴展名爲.exe。 – lit
@lit我試過 'subprocess.Popen(「C:\\ Windows \\ System32 \\ devcon.exe restart」sd0007322081041363_kcanv \「」,shell = True,stdout = subprocess.PIPE).stdout.read ()'但結果幾乎相同。結果:''C:\ Windows \ System32 \ devcon.exe'不被識別爲內部或外部命令 – Budlog