5

I'm using PSExec in a test machine environment to start the setup package of the application to be tested as administrator, and then run tests as administrator where needed. PSExec is only used for the "run as" part here, no remote execution. The call looks like this:

c:\psexec -u Administrator -p adminpassword -w C:\SystemTests C:\SystemTests\run_system_tests.cmd ...

The problem is that Jenkins, our CI server, only captures PSExec's logo in the console output, but not the actual test printout:

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

C:\SystemTests\run_system_tests.cmd exited with error code 0.

The started script opens its own console window locally and prints everything in there. But it's not logged in Jenkins so we won't know what the script did and why things may have failed.

Is there an option to make PSExec print the started program's output to stdout, instead of the logo, and not open a console window?

  • I'm guessing you're looking for output from batch file "run_system_tests.cmd". If so, then mod it to redirect output to a log file. Let us know the results or if you need help. – Lizz Sep 24 '13 at 16:30
  • Lizz, you mean the called batch file (or whatever will be called) needs to print its output to a file on its own and this file should then be listed (type filename) after psexec - and shell redirection cannot be used with psexec? – ygoe Sep 24 '13 at 19:00
  • I may be wrong. Try superuser.com/a/201201/178092 which uses following syntax: 2>&1 | tee test.txt – Lizz Sep 26 '13 at 1:00
  • 1
    tee (if it's availabe for Windows) also generally requires redirection (which seems to be the issue here) and only adds the feature to get output on both, display and file. I only need the file, the desktop is unattended anyway. // Update: Actually I don't want the file, but the stdout to be captured... – ygoe Sep 26 '13 at 5:53
  • Check Rob Van der Woude's beautifully written pages for solution on redirecting batch output: www.robvanderwoude.com/redirection.php and www.robvanderwoude.com/battech_redirection.php – Lizz Sep 27 '13 at 23:04
3

I've found that you can split the PsExec output from the remote output this way ...

psexec \\wxesbbtlkS02 cmd /c C:\test.bat >tmpfile.txt 2>other.txt

so you get the PsExec output in the other.txt file, and the remote in tmpfile.txt

2

Researching nearly this exact issue I came across this technet forum thread.

The relevant post in the thread:

post on sysinternals by user bnyffele

I actually found that there is no difference between the various systems, but it depends on how you address the remote machine:

psexec \\hostA cmd        -> seperate window opens (if command is executed on \\hostA)
psexec \\127.0.0.1 cmd    -> cmd prompt in same window
psexec \\[IP address] cmd -> cmd prompt in same window
psexec \\localhost cmd    -> results in error message about localhost being a duplicate name.
psexec \\hostA.domain.com -> cmd prompt in same window

So, it seems that I only get a separate window, when I am executing psexec for the local machine and I am using the short hostname.

It appears that if you specify the local host IP address as the machine to run the command on you will get the output. I tested this myself, and while it didn't print the standard output in real time it did print it all to the same terminal when the script finished.

If you are trying to figure out how to do this using the system name instead of the IP address you can still make it work by adding a dot to the end of the host name as determined by another user several posts later in the same thread.

post on sysinternals by user bluechipps

Actually i just discovered a workaround that is almost painless. All you have to do is add a '.' after the shortname and it will still function the same but will then output properly to the same cmd window! Note the differences.


PS C:> psexec \hal ipconfig

PsExec v1.95 - Execute processes remotely
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com

ipconfig exited with error code 0.
PS C:>


PS C:> psexec \hal. ipconfig

PsExec v1.95 - Execute processes remotely
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com

Windows IP Configuration

Ethernet adapter Local Area Connection 2:

Connection-specific DNS Suffix . :#####
Link-local IPv6 Address . . . . . :#####
IPv4 Address. . . . . . . . . . . :#####
Subnet Mask . . . . . . . . . . . :#####
Default Gateway . . . . . . . . . :#####

ipconfig exited on hal. with error code 0.
PS C:>


1

if you escape the > character with a caret ^ you can pipe the output to a file. See below.

c:\psexec -u Administrator -p adminpassword -w C:\SystemTests C:\SystemTests\run_system_tests.cmd ^> outputfile.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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