Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

tasklist command not working

by sagarkha (Acolyte)
on Jul 15, 2011 at 12:25 UTC ( #914596=perlquestion: print w/replies, xml ) Need Help??
sagarkha has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

Tasklist command that is used to view task on a remote system is not working for me through perl script, however the same command works if i use it directly on windows command prompt.

open (OLDOUT, ">&STDOUT"); open (OLDERR, ">&STDERR"); open (STDOUT, ">c:\\Temp\\STDOut.txt") or die "Can't open STDOUT: $!"; open (STDERR, ">C:\\Temp\\STDERR.txt") or die "Can't open STDERR: $!"; system("tasklist /S /U sagarkha /P ****** ");

Replies are listed 'Best First'.
Re: tasklist command not working
by kennethk (Abbot) on Jul 15, 2011 at 14:18 UTC
    Output from system never goes through perl, so you cannot capture either STDERR or STDOUT via simple redirects like you have attempted. You would get something much closer to what you expect with backticks (see `STRING`):

    open (OLDOUT, ">&STDOUT"); open (STDOUT, ">c:\\Temp\\STDOut.txt") or die "Can't open STDOUT: $!"; print `tasklist /S /U sagarkha /P ******`;

    or possibly

    print `tasklist /S /U sagarkha /P ****** 2>&1`;

    If, on the other had, you need to keep your error stream and output stream independent, you will need to do some interprocess communication -- see, for example, perlipc or IPC::Open3.

Re: tasklist command not working
by jethro (Monsignor) on Jul 15, 2011 at 12:30 UTC
    "is not working". Come on, you can do better with your error description.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://914596]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2018-04-22 15:23 GMT
Find Nodes?
    Voting Booth?