1.

Solve : Logging events in batch file?

Answer»

Hello all,

I have created a simple batch file to restart multiple services on windows 2003 server. Pretty much I am just using NET stop and start to accomplish this. What I need to know is how to copy the output in the batch file to a log.

I use the FOLLOWING to log the date and time the batch file ran but I am unsure how to log the rest:

echo %date% %time% >> log

The batch produces the following type of output:

The Tpe service is starting.
The Tpe service was started successfully.

I would like that output to be copied into the log file.

Any help would be appreciated (new to batch files)

-DaveYou should be able to do this the same way you did the echo statement, with redirection:

command parameters >> log

Beware: Command requests for input will be redirected. The user will not see the requests and the batch file will hang WAITING for input. Example:

del *.* >> log

The "Are you sure (Y/N)?" message will be sent to the log file and wait for a response. The user will not see the prompt.

Happy Computing. 8-)Thanks for the INFO.

I am still not sure what the command would be to have the log say the following:

Date here
The Tpe service is starting.
The Tpe service was started successfully.

OK. I'm confused.

Quote

I have created a simple batch file to restart multiple services on windows 2003 server. Pretty much I am just using net stop and start to accomplish this. What I need to know is how to copy the output in the batch file to a log.

I use the following to log the date and time the batch file ran but I am unsure how to log the rest:

echo %date% %time% >> log

The batch produces the following type of output:

The Tpe service is starting.
The Tpe service was started successfully.

I would like that output to be copied into the log file.

If you used net start and net stop before, can you not simply redirect these commands to the log?

net stop servicename >> log
net start servicename >> log


I'm not familiar with the TPE service but you could also use the SC start servicename and sc stop servicename

It is also possible to capture command window output but you would need a non-batch script for that.

8-)


Discussion

No Comment Found