NAME
IO::Mux::IPC - exchange data with external command
INHERITANCE
IO::Mux::IPC
is a IO::Mux::Bundle
is a IO::Mux::Handler::Read
is a IO::Mux::Handler
IO::Mux::Bundle also extends IO::Mux::Handler::Write
is a IO::Mux::Handler::Write
is a IO::Mux::Handler
SYNOPSIS
my $mux = IO::Mux::Select->new; # or ::Poll
use IO::Mux::Open '|-|', '|=|';
my $pipe = $mux->open('|-|', $cmd, @cmdopts);
use IO::Mux::IPC;
my $ipc = IO::Mux::IPC->new(command => [$cmd, @cmdopts]);
$mux->add($ipc);
$pipe->getline(sub {print "$_[0]\n"});
DESCRIPTION
With this handler, you set-up a two way communication between the current process and some other process. This is not easy to program: you may need to play with timeouts every once in a while.
This module is based on IO::Mux::Bundle, because it will use two or three pipes to facilitate the communication.
METHODS
Constructors
- IO::Mux::IPC->new(OPTIONS)
-
-Option --Defined in --Default command <required> errors <true> fh IO::Mux::Handler <required> mode |=| name IO::Mux::Handler '|$cmd|' read_size IO::Mux::Handler::Read 32768 stderr IO::Mux::Bundle <undef> stdin IO::Mux::Bundle <required> stdout IO::Mux::Bundle <required> write_size IO::Mux::Handler::Write 4096
- command => COMMAND|ARRAY
-
The external command to be executed. Either the COMMAND needs to parameters, or you need to pass an ARRAY of the command name and all its parameters.
- errors => BOOLEAN
-
Include the stderr channel in the communication as well. These will be printed to STDERR by default.
- fh => FILEHANDLE
- mode =>
|-|
or|=|
-
In the
|-|
mode, only STDIN and STDOUT are processed. Specifing the|=|
has the same effect as setting theerrors
option: open a connection for STDERR as well. - name => STRING
- read_size => INTEGER
- stderr => IO::Mux::Handler::Read object
- stdin => IO::Mux::Handler::Write object
- stdout => IO::Mux::Handler::Read object
- write_size => INTEGER
- IO::Mux::IPC->open(MODE, (CMD, CMDOPTS)|(CMDARRAY, OPTIONS))
-
Open the pipe to read. MODE is either
|-|
or|=|
. When you need to pass additional OPTIONS to the implied new(), then you must use an ARRAY for command name and its optional parameters.example:
my $mux = IO::Mux::Poll->new; $mux->open('|-|', 'sort', '-u'); # no opts $mux->open('|-|', ['sort', '-u'], %opts); $mux->open('|-|', 'sort'); # no opts $mux->open('|-|', ['sort'], %opts);
Accessors
- $obj->childPid
-
The process id of the child on the other side of the pipe.
- $obj->connections See "Accessors" in IO::Mux::Bundle
- $obj->fh See "Accessors" in IO::Mux::Handler
- $obj->fh See "Accessors" in IO::Mux::Handler
- $obj->fileno See "Accessors" in IO::Mux::Handler
- $obj->fileno See "Accessors" in IO::Mux::Handler
- $obj->mode
-
The bits of the open mode.
- $obj->mux See "Accessors" in IO::Mux::Handler
- $obj->mux See "Accessors" in IO::Mux::Handler
- $obj->name See "Accessors" in IO::Mux::Handler
- $obj->name See "Accessors" in IO::Mux::Handler
- $obj->readSize([INTEGER]) See "Accessors" in IO::Mux::Handler::Read
- $obj->stderr See "Accessors" in IO::Mux::Bundle
- $obj->stdin See "Accessors" in IO::Mux::Bundle
- $obj->stdout See "Accessors" in IO::Mux::Bundle
- $obj->usesSSL See "Accessors" in IO::Mux::Handler
- $obj->usesSSL See "Accessors" in IO::Mux::Handler
- $obj->writeSize([INTEGER]) See "Accessors" in IO::Mux::Handler::Write
User interface
Connection
- $obj->close([CALLBACK]) See "Connection" in IO::Mux::Handler
- $obj->close([CALLBACK]) See "Connection" in IO::Mux::Handler
- $obj->timeout([TIMEOUT]) See "Connection" in IO::Mux::Handler
- $obj->timeout([TIMEOUT]) See "Connection" in IO::Mux::Handler
Reading
- $obj->readline(CALLBACK) See "Reading" in IO::Mux::Handler::Read
- $obj->slurp(CALLBACK) See "Reading" in IO::Mux::Handler::Read
Writing
- $obj->print(STRING|SCALAR|LIST|ARRAY) See "Writing" in IO::Mux::Handler::Write
- $obj->printf(FORMAT, PARAMS) See "Writing" in IO::Mux::Handler::Write
- $obj->say(STRING|SCALAR|LIST|ARRAY) See "Writing" in IO::Mux::Handler::Write
- $obj->write(SCALAR, [MORE]) See "Writing" in IO::Mux::Handler::Write
Multiplexer
Connection
- $obj->mux_init(MUX, [HANDLER]) See "Connection" in IO::Mux::Handler
- $obj->mux_init(MUX, [HANDLER]) See "Connection" in IO::Mux::Handler
- $obj->mux_remove See "Connection" in IO::Mux::Handler
- $obj->mux_remove See "Connection" in IO::Mux::Handler
- $obj->mux_timeout See "Connection" in IO::Mux::Handler
- $obj->mux_timeout See "Connection" in IO::Mux::Handler
Reading
- $obj->mux_eof(INPUT) See "Reading" in IO::Mux::Handler::Read
- $obj->mux_except_flagged(FILENO) See "Reading" in IO::Mux::Handler
- $obj->mux_except_flagged(FILENO) See "Reading" in IO::Mux::Handler
- $obj->mux_input(BUFFER) See "Reading" in IO::Mux::Handler::Read
- $obj->mux_read_flagged(FILENO) See "Reading" in IO::Mux::Handler
- $obj->mux_read_flagged(FILENO) See "Reading" in IO::Mux::Handler
Writing
- $obj->mux_outbuffer_empty See "Writing" in IO::Mux::Handler::Write
- $obj->mux_output_waiting See "Writing" in IO::Mux::Handler::Write
- $obj->mux_write_flagged(FILENO) See "Writing" in IO::Mux::Handler
- $obj->mux_write_flagged(FILENO) See "Writing" in IO::Mux::Handler
Service
Errors
- $obj->mux_error(BUFFER) See "Errors" in IO::Mux::Bundle
Helpers
- $obj->extractSocket(HASH)
- IO::Mux::IPC->extractSocket(HASH) See "Helpers" in IO::Mux::Handler
- $obj->extractSocket(HASH)
- IO::Mux::IPC->extractSocket(HASH) See "Helpers" in IO::Mux::Handler
- $obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IO::Mux::Handler
- $obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IO::Mux::Handler
- $obj->show See "Helpers" in IO::Mux::Handler
- $obj->show See "Helpers" in IO::Mux::Handler
SEE ALSO
This module is part of IO-Mux distribution version 0.11, built on January 26, 2011. Website: http://perl.overmeer.net/ All modules in this suite: "Any::Daemon", "IO::Mux", and "IO::Mux::HTTP".
Please post questions or ideas to perl@overmeer.net
LICENSE
Copyrights 2011 by Mark Overmeer. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html