将参数从Python脚本发送到批处理脚本

时间:2017-03-15 11:11:26

标签: python batch-file subprocess

我正在尝试将参数从Python脚本发送到批处理脚本,但批处理文件仍然失败。

这是Python脚本中的内容:

cond = 'a'
sp3 = subprocess.Popen([os.path.join(lua_caller_pth[:indx], 'lua_caller1.bat'), cond])

cond = 'b'
sp4 = subprocess.Popen([os.path.join(lua_caller_pth[:indx], 'lua_caller1.bat'), cond])

这是批处理脚本:

if %cond% == "a" (
    %CYGWINPATH%\bash -l -c "cd $START_DIR \ && cd .. \ && cd Debug \ && ./iv4_console.exe ../embedded/LUA/analysis/verbose-udp-toxml.lua &>../Object_Detection_Test_Script/xmllog1 \ && exit; bash";
)
if %cond% == "b" (
    %CYGWINPATH%\bash -l -c "cd $START_DIR \ && cd .. \ && cd Debug \ && ./iv4_console.exe ../embedded/LUA/analysis/verbose-udp-toxml.lua &>../Object_Detection_Test_Script/xmllog2 \ && exit; bash";
)

1 个答案:

答案 0 :(得分:0)

在你的剧本中

%cond% 

评估环境varibale cond ,它们尚未由您的python程序设置。

您需要评估批处理中的命令行参数,而不是评估环境。有关如何执行此操作的详细信息,请参阅Get list of passed arguments in Windows batch script (.bat)