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.

TrailJon
  • 111
  • 4
  • 1
    Did you try it from the command line, or using the full path to `VerifyWarehouseLoad.exe`? – Julie Pelletier May 19 '16 at 03:57
  • 1
    `START "title" [/D path] [options] "command" [parameters]` [Always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes ""](http://ss64.com/nt/start.html). – JosefZ May 19 '16 at 08:33
  • What the `@end` stands for? `'end' is not recognized as an internal or external command, operable program or batch file.` Use `exit /B` to [quit current batch script execution](http://ss64.com/nt/exit.html). – JosefZ May 19 '16 at 08:46
  • `name="Test"` [Defines the name of an existing ElastiCube in an ElastiCube server. Use the name parameter when you want to rebuild the ElastiCube](http://www.sisense.com/documentation/prism-shell-psm-exe/). I'd try using the full path to the `Test` ElastiCube. – JosefZ May 19 '16 at 09:34
  • You should note that the "@" symbol in front of a line in a batch file simply prevents that command string from echoing to the console. For example, in a batch file with the command "echo off" at the beginning, a user would actually see "echo off" written to the screen when it runs that command. With "@echo off", the user never sees the command string on the console. – SamErde May 19 '16 at 15:08
  • Agree with @JosefZ, the missing title was the first thing I saw. – CoveGeek May 24 '16 at 02:38

3 Answers3

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)

  • Thanks for the syntax correction. It may have caused other problems at some point, but that wasn't the problem in this particular case. – TrailJon May 20 '16 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"
)
TrailJon
  • 111
  • 4
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"
CoveGeek
  • 186
  • 1
  • 7