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