0

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

omega
  • 40,311
  • 81
  • 251
  • 474
  • 3
    Possible duplicate of [Windows Batch Script: Redirect ALL output to a file](http://stackoverflow.com/questions/15346863/windows-batch-script-redirect-all-output-to-a-file) – isaias-b Jan 25 '16 at 20:15

1 Answers1

3

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

Dennis van Gils
  • 3,487
  • 2
  • 14
  • 35