0

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.

Ankush
  • 2,454
  • 2
  • 21
  • 27

2 Answers2

0

Try using xCmd.exe which is an alternative to psexec which redirects the remote output to the local console from where you are running the code. I have tried to mix JAVA + PSEXEC very bad combination. But got good results in using xcmd.exe but one catch is that it works well with 32 bit OS uptil win 2k8. From win7 onwards this doesn't work that well.

Sunand
  • 1
0

You can use the -lo option to write PSExec output into file

Synopsys:

psexec \\<machine_ip_address> -u <username> -p <password> -lo <log_filename> <some_command>

Example:

psexec \\192.10.10.69 -u admin -p 12345 -lo paexec.log ipconfig
Jet
  • 661
  • 5
  • 11