Solved throw error msg from a bat file

May 18, 2010 at 01:09:13
Specs: Windows XP
hello guys,

can n e one tell me how to throw an error msg from a bat file.


if not %var1% equ %var2% throw myErrorMsg

thanks in advance

See More: throw error msg from a bat file

Report •

May 18, 2010 at 01:25:01
Not sure what you mean by throw but have you tried echo?

if not %var1% equ %var2% echo myErrorMsg

Report •

May 18, 2010 at 02:04:09
i tried
exit /b -1

it will exit with a errorCode i.e -1
but i want a string message

actually i am using a tool which can execute a batch file in a workflow. and in the workflow it can catch the errormsg or code.
and i want to catch the error msg to put it in a condition to proceed my workflow.

Report •

May 18, 2010 at 02:04:10
✔ Best Answer
You can also take it one step further and send the echo to stderr:

if not %var1% equ %var2% 1>&2 echo myErrorMsg

Edit: Beaten by a second!

To return a string you would have to pass an environment variable back, create a text file or have the echo'd output logged by the calling process.

Report •

Related Solutions

May 18, 2010 at 02:54:26
One thing on forgot to add is that if the strings are rather generic to windows you may be able to return a number and reference it with "net helpmsg x".

Here is a list I just generated on xp home:

Don't expect the file to stay up long, I only put it there because pastebin is down.

Report •

Ask Question