Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Capture::Tiny alternative

by melezhik (Monk)
on Mar 24, 2017 at 11:55 UTC ( [id://1185769]=note: print w/replies, xml ) Need Help??


in reply to Re: Capture::Tiny alternative
in thread Capture::Tiny alternative

HI Thanos1983! Looks like https://metacpan.org/pod/Capture::Tiny::Extended#Teeing-In-Realtime is what I need , thanks, will try it.

Replies are listed 'Best First'.
Re^3: Capture::Tiny alternative
by thanos1983 (Parson) on Mar 24, 2017 at 12:03 UTC

    Hello again melezhik ,

    Create and post some example where you will be testing your code so future visitors have a good starting point or ideas on how to implement it on their project(s).

    Keep the "force" strong :D.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      Yeah, sure. when I get something to show I will put it here.

      Meanwhile here is example of how simple script using Perl IPC to read from external program may hangs :

      
      $ cat test.pl
      
      my $cmd = '/usr/sbin/sshuttle -v -D -r  vagrant@127.0.0.1 192.168.0.0/24';
      
      open(OUT, "$cmd 2>&1 |") || die "can't fork: $!";
      
      while (my $l = <OUT>) {
        print $l;
      }
      
      

      When I run test.pl it hangs:

      $ perl test.pl
      Starting sshuttle proxy.
      Listening on ('127.0.0.1', 12300).
      c : connecting to server...
      vagrant@127.0.0.1's password:
      c : connected.
      Connected.
      
      ...
      
      ^C # I have to enter control C to finish my script
      
      

      When run the same command directly, it does not hang:

      
      $ /usr/sbin/sshuttle -v -D -r  vagrant@127.0.0.1 192.168.0.0/24
      Starting sshuttle proxy.
      Listening on ('127.0.0.1', 12300).
      c : connecting to server...
      vagrant@127.0.0.1's password:
      c : connected.
      Connected.
      $ # finishes without interruption ..
      

      Sshutle information could be found here - https://github.com/apenwarr/sshuttle
      But I provide it only __as example__. Probably other command will cause the same Perl/IPC behavior. Any ideas why?


      And yeah , with Capture::Tiny sshutle does not hang ...

        Hello again melezhik ,

        Try your command like this:

        my $cmd = `/usr/sbin/sshuttle -v -D -r vagrant@127.0.0.1 192.168.0.0/ +24`;

        Instead of this:

        my $cmd = '/usr/sbin/sshuttle -v -D -r vagrant@127.0.0.1 192.168.0.0/ +24';

        Read more about it here (How to run a shell script from a Perl program?).

        Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

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

    No recent polls found