1

I'm new to windows batch scripting, but I was able to get something working that I needed. It works when executing it manually, but when Task Manager executes the script, it doesn't complete. The Last Run Result is "(0xff)."

The script is simple:

@echo off for /f %%i in ('VerifyWarehouseLoad.exe') do set RESULT=%%i IF %RESULT%==1 ( start /wait /d "C:\Program Files\Sisense\Prism" psm ecube build name="Test" serverAddress="LocalHost" mode="restart" ) @end 

It runs fine with just the line beginning start /wait.

I executes a console app named VerifyWarehouseLoad (located in the same directory as the batch file, captures the output and if the value is 1 it runs the line in the IF block.

I'm reading that the (0xff) is a syntax error, but that doesn't seem right if it's processing fine outside of Task Scheduler...

Thanks for any help.

6

3 Answers 3

1
@end 

This would work, if the file would be javascript file (.js). Since you are using batch file, you should use exit /B n to quit batch file, where 'n' is exit code. (Source)

1
  • Thanks for the syntax correction. It may have caused other problems at some point, but that wasn't the problem in this particular case. Commented May 20, 2016 at 18:26
0

Thanks everyone who left suggestions in the comments.

I tried one modification at a time and the solution was adding the full path to VerifyWarehouseLoad.exe

I also remove the first and last lines because they really weren't need. The console window isn't even show when executed from the Task Scheduler.

Here's the final script that is working both manually AND via the Task Scheduler.

for /f %%i in ('C:\Temp\VerifyWarehouseLoad.exe') do set RESULT=%%i IF %RESULT%==1 ( start /wait /d "C:\Program Files\Sisense\Prism" psm ecube build name="Answers Administrator" serverAddress="LocalHost" mode="restart" ) 
0

I choose to produce a solution that is somewhat different and more simplistic:

@echo off <fullpath>\VerifyWarehouseLoad.exe 2>&1 | Find /i "1" IF [%ERRORLEVEL%] EQU [0] start "TitlePlaceholder" /wait /d "C:\Program Files\Sisense\Prism" psm ecube build name="Test" serverAddress="LocalHost" mode="restart" 

By not using () around the command, there are fewer syntax checks during batch file parsing.

%ERRORLEVEL% is the return value of the previous command which is 0 when the find command locates the search string.

2>&1 Will take the standard error output and join it into standard out to allow the | to process the entire output of the command

If the VerifyWarehouseLoad.exe uses a return value instead of printing the status to the screen you can directly check for that be skipping the find command.

@echo off <fullpath>\VerifyWarehouseLoad.exe IF [%ERRORLEVEL%] EQU [0] start "TitlePlaceholder" /wait /d "C:\Program Files\Sisense\Prism" psm ecube build name="Test" serverAddress="LocalHost" mode="restart" 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.