我遇到了一个与我正在执行的嵌套调用有关的问题。
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