I've a console application which does this
class Program
{
static void Main(string[] args)
{
Console.WriteLine("out");
Console.Error.WriteLine("err");
Environment.ExitCode = 5;
}
}
When I run above in cmd prompt I get following
C:\>C:\pstools\test\outnerr.exe >C:\pstools\test\out1.log 2>C:\pstools\test\err1.log
C:\>echo %errorlevel%
5
C:\>type C:\pstools\test\out1.log
out
C:\>type C:\pstools\test\err1.log
err
C:\>
which is what is expected.
Now if I run this in Run Window
cmd /c C:\pstools\test\outnerr.exe >C:\pstools\test\out2.log 2>C:\pstools\test\err2.log
This also works and creates out2.log and err2.log.
Now if If I use psexec to run the same. I want to create a log file. It doesn't matter if it is created on local machine or remote machine. So I run this command
C:\pstools\test\psexec.exe \\127.0.0.1 cmd /c C:\pstools\test\outnerr.exe >C:\pstools\test\out3.log 2>C:\pstools\test\err3.log
This doesn't create log files when executed from Run Window. But same works if run from command prompt.
What is it I need to change in above to make it create log files from Run Window ?
PS I've read many threads here and over internet about redirection issue with PsExec. I'm aware of the fact that PsExec manipulates streams to make remote operations interactive. Maybe that's the reason for this simple thing not working.