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

Well, we don't really know what your requirements are here, but if the task must run "as if on a command line" then you may have to spawn the jobs on their separate ptys. See IO::Pty. The program in question could be acting differently depending on isatty test.

Replies are listed 'Best First'.
Re^5: Capture::Tiny alternative
by melezhik (Monk) on Mar 25, 2017 at 20:53 UTC

    Could you please provide an example code how can I run external program using pty and read its stdout in real time ? Also I need to know if programm exit successfully , is it possible with pty ?

    Sorry, I have read IO::Pty docs and it is not very clear what should I do.

      Okay, here's an example of IO::Pty usage. I do not know if there are any modules out there to support such functionality.

      sub pty_spawn { my $pty = new IO::Pty; $pty->set_raw(); # stty -opost -echo! my $pid = fork // die; unless ($pid) { $pty->make_slave_controlling_terminal(); # $pty->slave->clone_winsize_from(\*STDIN); close STDIN; close STDOUT; open STDIN, "+>&", $pty->slave; open STDOUT, "+>&", $pty->slave; exit !exec @_; } close $pty->slave; return $pty; }

      Calling pty_spawn(@cmd) leaves you with the $pty handle (the master side), that you can read and write. You'll need an event loop if you plan to do both. But if you only read, it should be easy. And you've got the $pid to wait on as usual (for exit status).