in reply to Capture::Tiny alternative

Hello melezhik,

Have you tried (Capture::Tiny::Extended)?

From the documentation:

Capture::Tiny::Extended - Capture STDOUT and STDERR from from Perl, XS + or external programs (with some extras)

Update: Take a look also at (Handling program output in real time), maybe it will give alternative ideas.

Hope this helps, let us know.

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

Replies are listed 'Best First'.
Re^2: Capture::Tiny alternative
by dasgar (Priest) on Mar 24, 2017 at 22:39 UTC

    I've used Capture::Tiny, but was not aware of Capture::Tiny::Extended. After checking it out, I'm not sure that I would use it or recommend using it at this point.

    Here's what I found out when looking over both Capture::Tiny and Capture::Tiny::Extended:

    • In the Description section of Capture::Tiny:Extended, the author notes that it is a fork of Capture::Tiny to add some desired functionality. The latest version of the module was released August 4, 2011. That means that it was based on version 0.11 of Capture::Tiny (released May 19, 2001) - or an earlier version of Capture::Tiny.

    • According to the change log for Capture::Tiny, version 0.12 (released December 1, 2011) added functionality from Capture::Tiny::Extended (whose author was credited in the change log too).

    • The latest version of Capture::Tiny is version 0.46 (released February 25, 2017). Doing a quick scan through the change log, it looks like there have been some fixes applied to deal with issues with the tee functionalities.

    At this point, I would say that Capture::Tiny probably now has all of the functionality of Capture::Tiny::Extended (including the tee functionalities that the OP is interested in) and probably is implementing those functionalities better than Capture::Tiny::Extended. Of course, that's just my impression after a little bit of investigation (without doing any testing).

    Just thought that I'd share what I found in case it proves useful to others.

Re^2: Capture::Tiny alternative
by melezhik (Monk) on Mar 24, 2017 at 11:55 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 ...