Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re(2): I may be remotely depressed.

by brassmon_k (Sexton)
on Jan 03, 2002 at 00:31 UTC ( #135793=note: print w/ replies, xml ) Need Help??


in reply to Re(2): I may be remotely depressed.
in thread FTP question

What do you mean?

I tested the little Perl snippet on my SPARC and it produces the output on STDOUT for the "ps -ef" command. I don't get what you mean for "standard input". I know the handle is used for INPUT processing via a file Handle but what I suggested still works. It's probably not syntaticallly correct but it works perfect. Perl doesn't seem to care if the pipe (|) is in front. It does send the "ps -ef" command to STDOUT though I guarantee it...try it. I also found it convienient to give it a handle because then this guy can manipulate the data any way he wants to later on. I might be misunderstanding you though.

The Brassmon_k


Comment on Re: Re(2): I may be remotely depressed.
Re: Re: Re(2): I may be remotely depressed.
by brassmon_k (Sexton) on Jan 03, 2002 at 00:42 UTC
    I just tested yours...
    #!/usr/bin/perl -w open PH, "ps -ef|" or die; close PH;
    The result was not to the screen or STDOUT. The command was run like if you used the "system" function. It executed the command but didn't return it's output. I'm not nearly even close as being as good at Perl as you but maybe you got the pipe placement screwed up. (I could be dumb and I'm not understanding what this guy really wants) but my version of it does return the "ps -ef" commands output to the screen on STDOUT. I know my way isn't common but it's a really nice hack and works really good for what I use it for.

    Well I'm just offering what I thought the guy wanted. Perl is a lot of fun now that I'm understanding it better.
    WOO HOO!

      Output doesn't go to the screen because of the terminating pipe character ('|'), instead it goes to the PH file handle, which you must then *read*, using a loop like this:

      #!/usr/bin/perl -w # Note: the 'die' on the next line will probably never trigger open PH, "ps -ef|" or die "$!: opening pipe"; # your snippet was missing this loop: while (<PH>) { print; # or whatever ... } # Note that for pipes, most errors will come when you try to close it, + so # if the command line had a problem, you'd see this 'die' trigger, not # the one on the 'open' close PH or die "$!: opening pipe";

      dmm

      You can give a man a fish and feed him for a day ...
      Or, you can
      teach him to fish and feed him for a lifetime

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-12-20 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (97 votes), past polls