利用subprocess.call呼叫系統指令時
若指令的最後是反斜號 "\"
import subprocess
subprocess.call('dir e:\',shell=True)
會造成以下的錯誤
c:\Python27\python.exe -u "C:\Users\nkhc\Desktop\1.py"
Process started >>>
File "C:\Users\nkhc\Desktop\1.py", line 9
subprocess.call('dir e:\',shell=True)
^
SyntaxError: EOL while scanning string literal
<<< Process finished. (Exit code 1)
================ READY ================
解決方式
subprocess.call('dir e:\\',shell=True)
沒有留言:
張貼留言