stderr to a file from batch file

May 24, 2011 at 08:02:18
Specs: Windows 7
Hi all,

A novice here.

I have a very simple batch file and I would like to write only its stderr output to a txt file. The batch file contains only one line

mxmlc filename

I know that I don't need a batch file for this but I don't have any control over that part of the program.

so I know can do the following

mxmlc filename 2>>error.log

However, the file error.log will get created even if there was no error generated from the script.

I know I can use errorlevel but then I won't know what the error was. Somehow I need to capture the output from the command and then check for errorlevel and if error level is 1 then I can output the error to a log file, otherwise I don't need to write anything to error.log


See More: stderr to a file from batch file

Report •

May 25, 2011 at 08:53:49
@echo off
mxmlc filename 2> error.tmp
for %%j in (error.tmp) do if %%~zj gtr 0 type error.tmp >> error.log
del error.tmp

Report •
Related Solutions

Ask Question