Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
3 files changed, 18 insertions, 11 deletions
diff --git a/Changes b/Changes
index 7238169..d14733e 100644
--- a/Changes
+++ b/Changes
@@ -1,8 +1,13 @@
Revision history for Perl extension POSIX::Run::Capture.
+1.01 Fri Jan 31 09:16:30 2020
+ - Argument to the 'stderr' or 'stdout' can be a code reference,
+ glob (file handle) or scalar string. In the latter two cases,
+ the stream is redirected to the file handle or the named file.
1.00 Wed Aug 14 08:11:53 2019
- line monitor is called for every line, whether or not terminated
with a newline
0.02 Fri Dec 1 08:54:18 2017
- first release
diff --git a/capture.c b/capture.c
index d5828ea..a925692 100644
--- a/capture.c
+++ b/capture.c
@@ -150,13 +150,13 @@ capture_set_output(struct capture *cp, SV *cb[2], int strno)
static char *what[] = { "stdout", "stderr" };
croak("%s must be scalar, glob or code ref",
} else {
char *filename = SvPV_nolen(sv);
- int fd = open(filename, O_CREAT|O_TRUNC|O_RDWR, 0777);
+ int fd = open(filename, O_CREAT|O_TRUNC|O_RDWR, 0666);
if (fd == -1) {
croak("can't open file %s for writing: %s",
filename, strerror(errno));
cp->rc.rc_cap[strno].sc_storfd = fd;
cp->flags |= RCF_SC_TO_FLAG(RCF_SC_STORFD, strno);
diff --git a/lib/POSIX/Run/ b/lib/POSIX/Run/
index 57c7d57..35275c1 100644
--- a/lib/POSIX/Run/
+++ b/lib/POSIX/Run/
@@ -25,13 +25,13 @@ our %EXPORT_TAGS = ( 'all' => [ qw(
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
#our @EXPORT = qw();
-our $VERSION = '1.00_01';
+our $VERSION = '1.01';
require XSLoader;
XSLoader::load('POSIX::Run::Capture', $VERSION);
use constant {
@@ -65,14 +65,14 @@ POSIX::Run::Capture - run command and capture its output
use POSIX::Run::Capture;
$obj = new POSIX::Run::Capture(argv => [ $command, @args ],
program => $prog,
stdin => $fh_or_string,
- stdout => sub { ... },
- stderr => sub { ... },
+ stdout => $ref_or_string,
+ stderr => $ref_or_string,
timeout => $n);
$num = $obj->errno;
$num = $obj->status;
$num = $obj->length($chan);
@@ -91,13 +91,13 @@ POSIX::Run::Capture - run command and capture its output
$num = $obj->timeout;
Runs an external command and captures its output. Both standard error and
output can be captured. Standard input can be supplied as either a
-filehandle or a text. Upon exit, the captured streams can be accessed line
+filehandle or a string. Upon exit, the captured streams can be accessed line
by line or in one chunk. Callback routines can be supplied that will be
called for each complete line of output read, providing a way for synchronous
This module is for those who value performance and effectiveness over
portability. As its name suggests, it can be used only on POSIX systems.
@@ -144,24 +144,26 @@ following example monitor function prints its argument to STDOUT:
Notice that the last line read can lack the teminating newline character.
=item B<stdout> =E<gt> I<FH>
-Capture standard output and write it to the file handle I<FH>.
+Redirect standard output to file handle I<FH>. Obviously, the handle should
+be writable.
=item B<stdout> =E<gt> I<NAME>
Capture standard output and write it to the file I<NAME>. If the file
-exists, it will be truncated.
+exists, it will be truncated. Otherwise, it will be created with permissions
+of 0666 modified by the process' "umask" value.
=item B<stderr> =E<gt> I<$arg>
Sets the I<line monitor> function for standard error or redirects it to
-the file handle or file, depending on the type of I<$arg>. See the
-description of B<stdout> above.
+the file handle or file, depending on the type of I<$arg> (CODE reference,
+GLOB or scalar string). For details, see the description of B<stdout> above.
=item B<timeout>
Sets execution timeout, in seconds. If the program takes longer than B<$n>
seconds to terminate, it will be forcibly terminated (by sending the B<SIGKILL>
@@ -179,13 +181,13 @@ A simplified way of creating the object, equivalent to
Crates an empty capture object.
Whatever constructor is used, the necessary parameters can be set
or changed later, using B<set_argv>, B<set_program>, B<set_input>,
and B<set_timeout>.
-Monitors can be defined only when creating the object.
+Monitors and redirections can be defined only when creating the object.
=head2 Modifying the object.
The following methods modify the object:
=head3 $obj->set_program($prog)
@@ -290,13 +292,13 @@ standard output and error channels.
=head1 AUTHOR
Sergey Poznyakoff, E<lt>gray@gnu.orgE<gt>
-Copyright (C) 2017 by Sergey Poznyakoff
+Copyright (C) 2017-2020 by Sergey Poznyakoff
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

Return to:

Send suggestions and report system problems to the System administrator.