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.

In reply to Re: netstat on remote with perl (possible?) by marinersk
in thread netstat on remote with perl (possible?) by softestplease

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.