Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Open Control::CLI Command With Pipe

by ImJustAFriend (Scribe)
on Jun 02, 2017 at 13:18 UTC ( [id://1191945]=perlquestion: print w/replies, xml ) Need Help??

ImJustAFriend has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I think I'm trying to do something that's not possible... I am using Control::CLI to interact with remote servers. I have need in my script to watch a log file until certain lines are seen and react to them accordingly. I am trying to open the command with a pipe so I can read the output into my script, but it doesn't work. I've tried the only 2 things I can think of/find online, and both fail.

open(LOG, $NE_obj->cmd("tail -f /path/to/log |")); open(LOG, '$NE_obj->cmd("tail -f /path/to/log")|');

Any thoughts on how this could work? Is it even possible? Thanks in advance!

Replies are listed 'Best First'.
Re: Open Control::CLI Command With Pipe
by crusty_collins (Friar) on Jun 02, 2017 at 15:10 UTC
    You can do this, I had the same issue last year. This is my solution.
    sub waitForCmd { my $href = shift(@_); return if ( not defined $href->{settings}->{nohup} ); # wait for the file # sleep 1 while ( ! -e "$href->{settings}->{runfolder}/$href- +>{settings}->{logfile}" ); open( FH ,'<', "$href->{settings}->{runfolder}/$href->{setting +s}->{logfile}" ); # keep track of spinner # my @sails = map { "\b$_" } qw{- \ | /}; my $sail = 0; # now search each line for job completed # FILE: for (;;) { while (<FH>) { print $sails[$sail++ % @sails] ; last FILE, if ( $_ =~ /Stopping AppMonitor Co +nnector| Failure| Maximum return code ex +ceeded for the run /xi ); } seek(FH, 0, 1); } close (FH); return; }
    "We can't all be happy, we can't all be rich, we can't all be lucky – and it would be so much less fun if we were. There must be the dark background to show up the bright colours." Jean Rhys (1890-1979)
Re: Open Control::CLI Command With Pipe
by ImJustAFriend (Scribe) on Jun 02, 2017 at 16:12 UTC

    Thanks for the feedback, crusty_collins! I've been poking around while waiting on a reply here. A little more careful reading of the Perl doc for open revealed my mistake. Here's the command that worked appropriately:

    open(LOG, "-|", $NE_obj->cmd("tail -f /path/to/log"));

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-28 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found