简体   繁体   中英

Sending arguments from a Python script to a batch script

I'm trying to send arguments from a Python script to a batch script, but the batch file keeps failing.

This is what is written in the Python script:

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])

And this is the batch script:

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";
)

In your script

%cond% 

evaluates the environment varibale cond , that has not been set by your python program.

You need to evaluate the command line argument from your batch instead of evaluting the environment. See Get list of passed arguments in Windows batch script (.bat) for more information how to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM