mhn
mhn

Reputation: 2750

Issue with logging output of batch execution

I have a file batchfile.bat that has some 7zip and Mysql operations. I have a second batch file to execute this called executor.bat . The executor.bat file only has the below code

.\batchfile.bat >>output.txt

So i expect all execution output to be written into output.txt. However, when i double click on executor.bat, i see the command prompt open and some mysql error messages, are coming on this command prompt instead of moving into the output.txt file. On the other hand, i can see 7-zip command line output getting captured in the output.txt file.

How can i further redirect the messages on command prompt to go into the output.txt file

Upvotes: 0

Views: 788

Answers (2)

JosefZ
JosefZ

Reputation: 30113

The >> redirector appends a STDOUT (text output) to the target file, but mysql error messages are sent to STDERR (error text output). To redirect both output and errors to one file, use next syntax:

.\batchfile.bat >>output.txt 2>>&1

FYI, all numeric handles are:

STDIN     = 0  Keyboard input
STDOUT    = 1  Text output
STDERR    = 2  Error text output
UNDEFINED = 3-9

Upvotes: 2

SomethingDark
SomethingDark

Reputation: 14305

Error messages get sent to the command prompt through a different output pipe than regular messages.

Try updating executor.bat to .\batchfile.bat >>output.txt 2>>output.txt

Upvotes: 1

Related Questions