Perl module to Provide an open3 function with the same syntax as system
Perl
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/IPC/Open3
t
.gitignore
.hgtags
Changes
Makefile
README.pod
dist.ini
weaver.ini

README.pod

NAME

IPC::Open3::System - Provide an open3 function with the same syntax as system

VERSION

version 0.103510

SYNOPSIS

use 5.10.0; # For "say" function
use IPC::Open3::System qw( open3 );

my $command = "cat";
my $proc = open3($command);

# Info about the process
say "Started command: ", join " ", @{$proc->command};
say "Subprocess PID: $proc->pid";

# Send some input to the process:
print {$proc->in} "INPUT DATA";

# Read output
my @subprocess_output = readline $proc->out;
my @subprocess_errors = readline $proc->err;

DESCRIPTION

This is yet another module for running a program and communicating with it. I couldn't find any modules out there with a sane interface for running a subprocess and returning *all three* of its handles: STDIN, STDOUT, and STDERR, so I wrote one.

INTERFACE

open3

This is simply a shortcut for C<IPC::Open3::System->new>. The
syntax is similar to Perl's builtin C<system>. It creates and
returns a "process" object for the subprocess that it spawns. The
object is simply a container for the subprocess's filehandles,
which are describe below, under FIELDS.

new

The OO constructor for IPC::Open3::System. Pass it the same
arguments that you would pass to the builtin C<system>.

FIELDS

An IPC::Open3::System object has the following fields. Each can be accessed by a method of the same name (see SYNOPSIS for examples of each).

command

The command that was provided to the constructor.

pid

The PID of the subprocess that was started.

in
out
err

These three fields correspond, respectively, to the child process's STDIN, STDOUT, and STDERR. Note that the parent process (i.e. your Perl script) will be *writing* to in and *reading* from out and err.

DEPENDENCIES

autodie
IPC::Open3

This module is really a wrapper around IPC::Open3.

String::ShellQuote;
List::Flatten::Recursive

This is my own module. Not yet on CPAN.

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

Syntax-compatibility with builtin system

For most inputs, open3 (and new) should end up executing the same command as Perl's builtin system. However, this is not thoroughly tested. Test cases are appreciated.

Angle-operator syntax oddities

You have to read from a process object's filehandles using readline instead of the usual angle operators, because you can't put complicated things inside Perl's angle operator. Alternatively, you can assign the filehandles to variables and then use those variables as normal:

my $out = $proc->out;
my $output = <$out>;

Naming

The name of this module stinks. I can't think of a more descriptive name. Suggestions are welcome.

Please report any bugs or feature requests to rct+perlbug@thompsonclan.org.

INSTALLATION

See perlmodinstall for information and options on installing Perl modules.

AUTHOR

Ryan C. Thompson <rct@thompsonclan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Ryan C. Thompson.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.