Sign in to PrePAN

Shell::Run Execute shell commands using specific shell



            use Shell::Run;
            my $bash = Shell::Run->new(name => 'bash');

            my ($input, $output);

            # input and output, status check
            $input = 'fed to cmd';
            $bash->run('cat', $output, $input) or warn('bash failed');
            print "output is '$output'\n";
            # no input
            $bash->run('echo hello', $output);
            print "output is '$output'\n";
            # use shell variable
            $bash->run('echo $foo', $output, undef, foo => 'var from env');
            print "output is '$output'\n";

            # use bash feature
            $bash->run('cat <(echo $foo)', $output, undef, foo => 'var from file');
            print "output is '$output'\n";


The Shell::Run class provides an alternative interface for executing shell commands from a perl script


Unless I'm missing something, you could use this with most Linux/Unix shell (csh, ksh, etc) and Bash is just the default shell it uses if you don't tell it differently. It would be great if you had the option of exporting the `bash` function under other names (possibly user defined).

If you do get is to have a more generic interface then you'd want to rename the module to something more generic as well (`Shell::Run` and `Shell::Call` spring to mind as possibilities, but you can probably come up with something better).
Could you explain how this differs from IPC::Run? They both address the same need. IPC::Run is rather battle tested, so any new entry into this space has stiff competition. Thanks for your efforts!
Thanks for your comments! I definitely have to rethink this. What I want to do is have the shell (i.e. bash - not sh) do some parameter processing like 'cmd <(echo "$var")' where stdin and $var are given as perl variables and stdout is captured into a perl variable, too. I'll have a look at this when I'm back from vacations.
Did some major rework. As a class, it doesn't export the bash sub any longer and is no longer bash specific.
Compared to IPC::Run the usage shall be easier for just the special case of calling a small piece of shell code.
The main usage is something like signature="$(echo -n "$signdata" | openssl dgst -sha256 -sign <(echo "$key") -hex", which needs some extra effords even with IPC::Run.

Please sign up to post a review.