App-column-run
view release on metacpan or search on metacpan
lib/App/column/run.pm view on Meta::CPAN
for my $i (0..$#{$commands}) {
my $cmd = $commands->[$i];
if (@$common_command_args) {
$cmd .= " " . ShellQuote::Any::PERLANCAR::shell_quote(@{ $common_command_args });
}
if ($command_args_arrays->[$i] && @{ $command_args_arrays->[$i] }) {
$cmd .= " " . ShellQuote::Any::PERLANCAR::shell_quote(@{ $command_args_arrays->[$i] });
}
log_trace "Command[%d]: %s", $i, $cmd;
%ENV = %orig_env;
$ENV{COLUMNS} = $gargs{column_width};
$ENV{$_} = $common_envs->{$_} for keys %$common_envs;
log_trace("Setting env for command[%d]: %s=%s", $i, $_, $common_envs->{$_}, $i) for keys %$common_envs;
$ENV{$_} = $command_envs_arrays->[$i]{$_} for keys %{ $command_envs_arrays->[$i] // {} };
log_trace("Setting env for command[%d]: %s=%s", $i, $_, $command_envs_arrays->[$i]{$_}) for keys %{ $command_envs_arrays->[$i] // {} };
my ($out, $err);
IPC::Run::run(
sub {
system $cmd;
if ($?) { die "Can't system($cmd):, exit code=".($? < 0 ? $? : $? >> 8) }
},
\$stdin,
\$out,
\$err,
);
$texts[$i] = $out;
}
%ENV = %orig_env;
\@texts;
}, # _gen_texts
);
}
1;
# ABSTRACT: Run several commands and show their output in multiple columns
__END__
=pod
=encoding UTF-8
=head1 NAME
App::column::run - Run several commands and show their output in multiple columns
=head1 VERSION
This document describes version 0.005 of App::column::run (from Perl distribution App-column-run), released on 2021-07-08.
=head1 DESCRIPTION
Sample screenshots:
=begin html
<img src="https://st.aticpan.org/source/PERLANCAR/App-column-run-0.005/share/images/Screenshot_20210625_085610.png" />
=end html
=begin html
<img src="https://st.aticpan.org/source/PERLANCAR/App-column-run-0.005/share/images/Screenshot_20210625_094844.png" />
=end html
=head1 FUNCTIONS
=head2 column_run
Usage:
column_run(%args) -> [$status_code, $reason, $payload, \%result_meta]
Run several commands and show their output in multiple columns.
This utility is similar to using the Unix utility L<pr> to columnate output,
something like (in bash):
% pr -T -m -w $COLUMNS <(command1 args...) <(command2 args...)
except with the following differences:
=over
=item * commands are run in sequence, not in parallel (although parallel execution is
a TODO list item);
=item * all output are collected first, then displayed (although streaming output is a
TODO list item);
=item * multiplexing STDIN to all commands;
=item * ANSI color and wide character handling;
=item * passing adjusted COLUMNS environment to commands so they can adjust output;
=item * passing common arguments and environment variables to all commands (as well as
allowing each command to have its unique arguments or environment variables).
=back
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<args_arrays> => I<array[aos]>
Arguments to give to each command (an array of arrays of strings).
If C<--common-args> is also set, then the common arguments will be added first,
then the per-command arguments.
=item * B<commands>* => I<array[str]>
=item * B<common_args> => I<array[str]>
Common arguments to pass to each command.
( run in 3.075 seconds using v1.01-cache-2.11-cpan-df04353d9ac )