30

I have a windows batch file that looks similar to:

C:\DoStuff.cmd
move output.bak C:\newfolder\output.bak

The problem i have is that DoStuff.cmd executes a java program that once complete exits the batch run back to the command prompt. Line 2 never gets hit.

i have tried the following instead to execute the command in a new window:

start "My program" /WAIT C:\DoStuff.cmd
move output.bak C:\newfolder\output.bak

What happens with the above is that the new command window spawns the cmd file runs and exits back to a waiting command prompt and the window never closes, leaving the first command window waiting and the second doing nothing stuck after finishing step one.

How do i execute the first command without it having control of the batch run somehow?

many thanks in advance

1 Answer 1

44

You can use DOS call command:

@echo off
call C:\DoStuff.cmd
echo Exit Code = %ERRORLEVEL%

After getting error code you can proceed for example with:

if "%ERRORLEVEL%" == "1" exit /B 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.