General discussion

Locked

logging the results of a batch file

By donalconlon ·
Hi,
We have a batch file which runs weekly at night that updates anti virus software on client computers. What is the syntax to output the results of this or any other batch file to a simple text file. Thanks.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

logging the results of a batch file

by VinnyD In reply to logging the results of a ...

Here is a sample of a batch file I use that sends the starndard output to a text file.

net start "Microsoft Exchange Event Service" > C:\strtexch.log
net start "Microsoft Exchange Internet Mail Service" >> C:\strtexch.log

The > sign sends theoutput from the net start command into the file called c:\strtexch.log.

The > by itself creates the file or writes over an existing file.

The >> you see on the 2nd line of the sample appends the test to the log file.

Collapse -

logging the results of a batch file

by donalconlon In reply to logging the results of a ...

Thanks. Good to know how to append as well as overwrite the file.

Collapse -

logging the results of a batch file

by BeerMonster In reply to logging the results of a ...

Hi,
Just a quick addition to the last respondent's comments. When the command interpreter echoes to the screen or a file it does so using one of two 'streams' - standard out and error out. You may find that, although the > and >> will work for the majority of the time, occasionally a command (such as a net use etc) will fail and the output will NOT be logged to your batch file (you can test this by typing "net stop nonexistentservice >> mylog.txt" - obviously without the quotes - you will see that the logfile is empty afterwards although an error was displayed onscreen). this is because the error message is being passed to a different output stream (the error out) which is not picked up by the > and >> redirection methods. To get round this use 2>&1 eg

net stop myservice 2>&1 >> mylog.txt

Hope this helps

Collapse -

logging the results of a batch file

by donalconlon In reply to logging the results of a ...

Thanks again. I will bear this in mind if this problem arises. Have a beer on me.

Collapse -

logging the results of a batch file

by donalconlon In reply to logging the results of a ...

This question was closed by the author

Back to Windows Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums