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

Jerold Schulman

April 6, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


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 . . .:errcall StdErr "Line %line% has an error.". . .

StdErr.bat contains:

@echo offsetlocalif 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":outif {%1}=={} goto outNonecscript //nologo "%TEMP%StdErr.vbs" %1endlocalgoto :EOF:outNonecscript //nologo "%TEMP%StdErr.vbs" "No Parameter Provided."endlocal



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like