JSI Tip 9232. How can my batch script output to StdErr?

I have scripted StdErr.bat to generate output on StdErr, so that it is separate from the normal output on StdOut.

The syntax for using StdErr.bat is:

\[call\] StdErr Message

Where Message is a double-quoted string that you wish to display on StdErr.

Sample Usage:

If you wanted to redirect the output of a script to a file, but provide immediate display of some messages:
. . .
. . .
If "%AOK%" EQU "N" goto err
@echo %line%>>%ReportFile%
. . .
goto . . .
call StdErr "Line %line% has an error."
. . .
StdErr.bat contains:
@echo off
if exist "%TEMP%\StdErr.vbs" goto out
@echo dim err>"%TEMP%\StdErr.vbs"
@echo Set objshell = CreateObject("WScript.Shell")>>"%TEMP%\StdErr.vbs"
@echo Set objArgs = WScript.Arguments>>"%TEMP%\StdErr.vbs"
@echo err=objArgs(0)>>"%TEMP%\StdErr.vbs"
@echo WScript.StdErr.Writeline err>>"%TEMP%\StdErr.vbs"
if \{%1\}==\{\} goto outNone
cscript //nologo "%TEMP%\StdErr.vbs" %1
goto :EOF
cscript //nologo "%TEMP%\StdErr.vbs" "No Parameter Provided."

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.