我遇到了一個與我正在執行的嵌套調用有關的問題。
RunProgram()-> cmd-> Python
下面的bat文件可以很好地工作。
set JMP_PYTHON_PTH=%UserProfile%\miniconda_JMP\
CALL %JMP_PYTHON_PTH%\Scripts\activate.bat %JMP_PYTHON_PTH%
start /B /wait "" python test.py
但是,當使用RunProgram()時,除非我將絕對路徑添加到Python文件(test.py->'C:/a/b/c/test.py'),否則代碼將失敗。
ClearLog();
file_path = ConvertFilePath( "./tests/run_python_installation_test.bat", windows);
rp = RunProgram( Executable( "cmd.exe" ),
Options( {"/C", file_path} ),
ReadFunction("text") // returns all text
);同樣,僅在未提供絕對路徑的情況下,我得到的錯誤如下。
(base) C:\WINDOWS\system32>start /B /wait \!"\!" python test.py
python: can't open file 'test.py': [Errno 2] No such file or directory
當我運行這個
file_path = convertfilepath("$temp/x.bat","windows");
savetextfile(file_path, "dir\!n");
rp = RunProgram( Executable( "cmd.exe" ),
Options( {"/C", file_path} ),
ReadFunction("text") // returns all text
);似乎bat文件執行的工作目錄是我的桌面目錄。 我認為python也會使用工作目錄在命令行上查找文件名。 使用完整路徑名似乎是一個不錯的選擇。
https://superuser.com/questions/396394/how-do-i-set-an-executables-working-directory-via-the-command-line-prior-to-ex建議您可以在啟動命令中指定工作目錄:
START /D c:\temp notepad.exe