Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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 10.9.79.251 /U sagarkha /P ****** ");

Comment on tasklist command not working
Download Code
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.
Re: tasklist command not working
by kennethk (Monsignor) 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 10.9.79.251 /U sagarkha /P ******`;

    or possibly

    print `tasklist /S 10.9.79.251 /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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://914596]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2014-07-29 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (220 votes), past polls