Search code examples
pythonbatch-filecmdwlst

Calling CMD commands sequentially (WLST Python Scripts)


I know there are many questions around sequentially calling shell commands from a batch file. However, I am unable to get through this peculiar issue, mainly while calling Oracle WebLogic (WLST) Python scripts.

I have a batch file, which at a high level does these things:

  1. Copies some files to their designated location
  2. Starts Oracle WebLogic server
  3. Calls script1.py to configure something on Admin Server
  4. Calls some other shell commands
  5. Calls script2.py to configure something else on Admin Server

Snippet from the file:

:: set some paths
FOR /F "tokens=1,2 delims==" %%G IN (config.properties) DO (set %%G=%%H) 

:: copy files
call copyFiles.bat

:: start the server
start startWebLogic.cmd

:: execute script 1
set _JAVA_OPTIONS="-XX:MaxHeapSize=512m"
%WLST_PATH%\wlst.cmd script-1.py

:: some more DOS commands

:: execute script 2 
%WLST_PATH%\wlst.cmd script-2.py

The problem is in steps 3 and 5. Whenever wlst initializes and starts execution, it owns the console and starts printing the output on the console. Once done, it won't execute the next script commands at all. The execution simply stops then and there. The control just ends inside %WLST_PATH%.

As a workaround, I am using start and timeout commands.

:: execute script 1
set _JAVA_OPTIONS="-XX:MaxHeapSize=512m"
start /MIN wlst.cmd %WLST_PATH%\wlst.cmd script-1.py
timeout /t 40 /nobreak

:: some more DOS commands

:: execute script 2 
start /MIN wlst.cmd %WLST_PATH%\wlst.cmd script-2.py
timeout /t 40 /nobreak

I have also tried using call but it didn't help, and it results in the same problem as mentioned above. Is there a better way to do it? What I want is that all these commands should get executed in sequence.


Solution

  • As suggested by eryksun, this issue was resolved by using:

    cmd /c ""%WLST_PATH%\wlst.cmd" script-1.py"