in reply to netstat on remote with perl (possible?)

Interesting. I haven't used psexecin awhile, but it's coming back to me as I play with this.

The problem is that psexeccan only run a program. The following summarizes my test:

FAILURE: psexec dir C:\RmtTools SUCCESS: psexec cmd /c dir C:\RmtTools FAILURE: psexec cmd /c dir C:\RmtTools | sort /r

  1. dirfails because it is not a program (not a transient command). It is a resident command, which is not a program.
  2. cmd /c dirworks because cmdis a transient command -- an executable program in its own right. It happens to process the command line with the /coption, so basic command line rules apply and dirtherefore works.
  3. One of two things is failing with the use of a pipe in this third example; either psexecis filtering it out before sending it, or it is not being handled properly on the other end by the cmdprogram.

The full test is hidden behind the readmore tag below.

HOW I SOLVED THIS IN THE PAST: My suggestion is to copy a batch file to the remote system which has your commands in it, and which redirects its final output to a file; then use psexecto execute that batch file; then copy the results file back and parse it.

If you can, it is handy to create a Unique but Known directory on the remote system where such things can be deposited.

There are other ways to work around this limitation -- but psexeccan only run one program -- it does not, in the strictest sense, execute a command line. Pipes are not part of that operating condition.

C:\Steve\Dev\PerlMonks\P-2013-10-24@0940-BackTick-Pipe>psexec \\system +name -u "DOMAIN\User Name" -p password dir C:\RmtTools PsExec v1.94 - Execute processes remotely Copyright (C) 2001-2008 Mark Russinovich Sysinternals - www.sysinternals.com PsExec could not start dir on systemname: The system cannot find the file specified. C:\Steve\Dev\PerlMonks\P-2013-10-24@0940-BackTick-Pipe>psexec \\system +name -u "DOMAIN\User Name" -p password cmd /c dir C:\RmtTools PsExec v1.94 - Execute processes remotely Copyright (C) 2001-2008 Mark Russinovich Sysinternals - www.sysinternals.com Volume in drive C has no label. Volume Serial Number is 1402-8CDA Directory of C:\RmtTools 10/24/2013 10:09 AM <DIR> . 10/24/2013 10:09 AM <DIR> .. 10/24/2013 09:50 AM 22 test.dat 10/24/2013 09:50 AM 22 test1.dat 10/24/2013 09:50 AM 22 test2.dat 10/24/2013 09:50 AM 22 test3.dat 4 File(s) 88 bytes 2 Dir(s) 17,756,794,880 bytes free cmd exited on systemname with error code 0. C:\Steve\Dev\PerlMonks\P-2013-10-24@0940-BackTick-Pipe>psexec \\system +name -u "DOMAIN\User Name" -p password cmd /c dir C:\RmtTools | sort +/r PsExec v1.94 - Execute processes remotely Copyright (C) 2001-2008 Mark Rusorts: sopen failed: /ri: nNo such file + or directoryo ich Sysinternals - www.sysinternals.com cmd exited on systemname with error code 0.