Re: stderr to a file from a batch script
Since you are appending data to the log file, I assume you want the log to preserve errors from prior runs. Once the log is created (empty or not) it is not re-created on subsequent runs. So it seems to me you could simply ignore the empty file. The log file will remain empty until the 1st run that generates an error. Only runs that generate errors will impact the log once it has been created.
If you really don't want the empty file, you can delete the log if it is empty based on the file size attribute:
for %%f in (error.log) do if %%~zf==0 del %%f
I can envision that you might want some form of timestamp before each run's errors, and you would not want the timestamp unless there were errors. For that you can use a temporary file.
set timestamp=%date% %time%
mxmlc filename 2>%tempFile%
for %%f in (%tempFile%) do (
if %%~zf gtr 0 (
Note that this last strategy will not create the log file until a run generates an error, as you requested.(Code was edited after initial submission to compute timestamp before running the program - dbenham)