0

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";
)
Mohamed Ameen
  • 65
  • 1
  • 8
  • You're just passing the string 'a' as an argument, how does the batch script associate that with %cond%? You'd probably be better off using subprocess.call(). – Simon Hibbs Mar 15 '17 at 11:26
  • In the batch you've to use `%1` to receive the first command line argument not `%cond%`. –  Mar 15 '17 at 12:04

1 Answers1

0

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.

Community
  • 1
  • 1
sb9
  • 1,082
  • 7
  • 18