omega
omega

Reputation: 43893

How to redirect net command output to file in windows batch file?

I want to redirect the statements it puts on the console into a file in windows batch code. I am using the net stop command to stop a service.

When I do this:

net stop SPTimerV4 2>> mylog.log

it appends error text into the file. But it still prints the regular text on the console:

The SharePoint 2010 Timer service is stopping.
The SharePoint 2010 Timer service was stopped successfully.

How can I even redirect this to a file?

Thanks

Upvotes: 0

Views: 2586

Answers (1)

Dennis van Gils
Dennis van Gils

Reputation: 3462

net stop SPTimerV4 >> mylog.log 2>&1 is what you're looking for.

This works by redirecting all normal output to the log file (the >>) and redirecting error output a copy of the normal output at that moment, which is appending to a file.

Because it redirects to a copy, you can't actually switch them around (eg. 2>&1 1>> mylog.log won't work)

For more information regarding redirection, please look here

Upvotes: 3

Related Questions