1

This question already has an answer here:

I'm creating a script to do rebooting of computers, and I need to report the success or failure of the shutdown.exe command as part of my script logging. I'm having an issue with redirecting the output of failed shutdown.exe processes to a file. Here is my command line:

shutdown.exe -r -t 50000 -m \\top34.top.local > c:\output.txt

When I run this, I see the following message on my screen: "top34.top.local: The entered computer name is not valid or remote shutdown is not supported on the target computer. Check the name and then try again or contact your system administrator.(53)", which is I am expecting, but c:\output.txt is blank - and does not contain this error. My script needs to output this line to a text file for logging purposes.

I have also tried to wrap it around a CMD, like such:

cmd /c shutdown.exe -r -t 50000 -m \\top34.top.local > c:\output.txt

But this too produces no result. I have also tried the double >> (append), but this makes no difference.

I've done a fair bit of investigation, and it appears that shutdown.exe will redirect output of successful commands to stdout, but not failed commands. How can I get it to redirect both successful and failed commands to my file?

Running Windows 2012 R2

marked as duplicate by and31415, Kevin Panko, MariusMatutiae, Moses, Dave Aug 22 '14 at 10:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

How can I get it (shutdown) to redirect both successful and failed commands to my file?

Use the following command:

shutdown.exe -r -t 50000 -m \\top34.top.local > c:\output.txt 2>&1

Note that the 2>&1 should be after the first > redirect.


Duplicating handles

The & redirection operator duplicates output or input from one specified handle to another specified handle. For example, to send dir output to File.txt and send the error output to File.txt, type:

dir > c:\file.txt 2>&1

Source Using command redirection operators

  • The "dir" command redirects as it should and as you pointed out, but the shutdown command does not. I get 0-byte files from using "shutdown.exe" in place of "dir". CMD: shutdown.exe -r -f -t 600 > out.txt 2>&1 – prl77 Oct 31 '16 at 23:27
  • Never mind, this was a total user error on my part. – prl77 Nov 1 '16 at 15:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.