我想從Python中執行以下Windows 7的命令:使用Python來設置Windows路徑和調用多個命令
SET PATH=%PATH%;C:\Qt\Qt5.5.1\5.5\mingw492_32\bin;C:\Qt\Qt5.5.1\Tools\mingw492_32\bin
C:\Qt\Qt5.5.1\5.5\mingw492_32\bin\qmake untitled5.pro
C:\Qt\Qt5.5.1\Tools\mingw492_32\bin\mingw32-make
C:\Qt\Qt5.5.1\Tools\mingw492_32\bin\mingw32-make clean
我想:
os.system("SET PATH=%PATH%;C:\\Qt\\Qt5.5.1\\5.5\\mingw492_32\\bin;C:\\Qt\\Qt5.5.1\\Tools\\mingw492_32\\bin")
os.system("qmake untitled5.pro")
os.system("mingw32-make.exe")
os.system("mingw32-make clean")
不過的了:
'qmake' is not recognized as an internal or external command,
operable program or batch file.
'mingw32-make.exe' is not recognized as an internal or external command,
operable program or batch file.
'mingw32-make' is not recognized as an internal or external command,
operable program or batch file.
看來PATH沒有改變。有人會提出一個想法嗎?
如果我把這些命令放在cmd.bat
然後調用os.system("cmd.bat")
它就起作用了。但我寧願不創建這個額外的文件(cmd.bat
)。
創建['subprocess.Popen'](https://docs.python.org/2/library/subprocess.html?highlight=popen#subprocess.Popen)類的一個實例和通過'env'關鍵字參數傳遞你想要的環境。 – martineau
爲什麼你需要使用python呢? –
我打算從Jenkins調用Python腳本。到目前爲止,我正在使用Bash和/或Bat腳本。 – KcFnMi