IPC::OpenAny - Run a process with control over any FDs it may use.
version 0.005
use IPC::OpenAny qw(openany); open my $fh, '>', 'fd3_out.txt'; my $cmd_sub = sub { print STDOUT "foo1\n"; print STDERR "foo2\n"; my $fd3_fh = IO::Handle->new_from_fd(3, '>'); print $fd3_fh "foo3\n"; }; # call the class method my $pid = IPC::OpenAny->run( cmd_spec => $cmd_sub, fds => { 0 => undef, # close this 1 => \*STDERR, # foo1 2 => \*STDOUT, # foo2 3 => $fh, # foo3 }, wait => 1, ); # OR use the exported sub open my $fd1_fh, '<', $0; my $pid2 = openany( cmd_spec => [qw(tr a-zA-Z n-za-mN-ZA-M)], fds => { 0 => $fd1_fh, }, );
THIS SOFTWARE IS STILL UNDER DEVELOPMENT PLEASE REPORT ANY BUGS, COMMENTS, OR FEATURE REQUESTS
In the spirit of IPC::Open2 and IPC::Open3, which give you 2 and 3 handles to a child process, IPC::OpenAny makes it easy to start a process with any file descriptors you want connected to whatever handles you want.
Runs the given command or code-ref in a separate process, with its file descriptors mapped to handles or closed (or just left alone) however the user may choose.
Accepts the following parameters:
This specifies the command or code to be executed. If it is a string, it will be passed to exec() which will invoke it via the shell. If it is a coderef, that coderef will be executed in a sepearate process just like a system command. If it is an arrayref, the first element will be used as the system command to execute, and the remaining elements will be the arguments passed to it. (string | coderef | arrayref)
Set this to a hashref where the keys are file descriptor numbers in the child process and the values are either perl file handles or undef. (hashref)
Set this to a hashref where the keys are the names of environment variables and the values are the values you want set for those env vars when the process is executed. (hashref)
Set this to the path you want to be the working directory of the process that will be executed. (string)
This exportable sub is just a thin wrapper around the "run" method above. It takes the exact same parameters.
IPC::Open2
IPC::Open3
IPC::Run
IPC::Cmd
May not work on Win32, and I don't have a windows box with which to develop and test it. Patches welcome!
As usual, please report any other issues you may encounter!
Stephen R. Scaffidi <sscaffidi@cpan.org>
This software is copyright (c) 2012 by Stephen R. Scaffidi.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install IPC::OpenAny, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IPC::OpenAny
CPAN shell
perl -MCPAN -e shell install IPC::OpenAny
For more information on module installation, please visit the detailed CPAN module installation guide.