document updated 28 days ago, on Jun 3, 2022
The goal is to run a command, ala system() or readpipe(), and capture the STDOUT and/or STDERR.
I find myself having to do this a lot , but especially when running basic Git commands .
my own readpipe_args()
, readpipe_args_chomp()
, and readpipe_ultimate()
pro — they use wantarray
to determine whether to return the output as a single string or split up into individual lines
con — they can only capture STDOUT, never STDERR
con — it's a bad idea to use Perl Golf in production scripts
IPC::System::Simple — 130 reverse dependencies
pro — uses wantarray
to determine whether to return the output as a single string or split up into individual lines
con — doesn't have the tee()
functionality that Capture::Tiny
does
con — can only capture STDOUT, never STDERR
Capture::Tiny — 656 reverse dependencies
pro — can capture STDOUT, STDERR, or both
pro — can tee
things, to send the output both to $captured_string as well as to the terminal
con — doesn't use wantarray
to decide whether to return the output as a single string or split up into individual lines
System::Command — 5 reverse dependencies
background — This was created at the same time Git::Repository::Command was being created, and they have a nearly identical interface.
note — you should use the spawn()
routine, if the other modules here appeal to you, unless you need the more-verbose interface of the rest of the module
con — doesn't have the tee()
functionality that Capture::Tiny
does
con — doesn't use wantarray
to decide whether to return the output as a single string or split up into individual lines
(though it does have the loop_on()
functionality)
pro — has the ability to specify a string that will be piped in via the processes' STDIN
con — doesn't have the ability to just capture STDOUT and leave STDERR untouched, to go to the user's terminal
Backticks
about a trillion more
these incorporate and are based on Capture::Tiny
Command::Runner — 3 reverse dependencies
con — it can either capture both STDOUT and STDERR, or capture them merged together (see _wrap()
inside its source )
con — doesn't use wantarray
to decide whether to return the output as a single string or split up into individual lines
(though runns the callback for each line returned, which means it always processes the outpu split up into individual lines)
Capture::SystemIO — 0 reverse dependencies
con — always captures both STDOUT and STDERR, it doesn't have the ability to just capture one or the other
con — doesn't use wantarray
to decide whether to return the output as a single string or split up into individual lines