view release on metacpan or search on metacpan
libuv/ChangeLog view on Meta::CPAN
* android: fix compilation warning (Saúl Ibarra Corretgé)
* unix: don't close the fds we just setup (Sam Roberts)
* test: spawn child replacing std{out,err} to stderr (Saúl Ibarra Corretgé)
* unix: fix swapping fds order in uv_spawn (Saúl Ibarra Corretgé)
* unix: fix potential bug if dup2 fails in uv_spawn (Saúl Ibarra Corretgé)
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
add_stopwords($config->{pod_spelling_system}->{stopwords}->@*);
add_stopwords(qw(
Plicease
stdout
stderr
stdin
subref
loopback
username
os
view all matches for this distribution
view release on metacpan or search on metacpan
inc/inc_IPC-Cmd/IPC/Cmd.pm view on Meta::CPAN
print "fetched webpage successfully: $buffer\n";
}
### in list context ###
my( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
run( command => $cmd, verbose => 0 );
if( $success ) {
print "this is what the command printed:\n";
print join "", @$full_buf;
inc/inc_IPC-Cmd/IPC/Cmd.pm view on Meta::CPAN
print "IPC::Open3 available: " . IPC::Cmd->can_use_ipc_open3;
print "IPC::Run available: " . IPC::Cmd->can_use_ipc_run;
print "Can capture buffer: " . IPC::Cmd->can_capture_buffer;
### don't have IPC::Cmd be verbose, ie don't print to stdout or
### stderr when running commands -- default is '0'
$IPC::Cmd::VERBOSE = 0;
=head1 DESCRIPTION
IPC::Cmd allows you to run commands, interactively if desired,
inc/inc_IPC-Cmd/IPC/Cmd.pm view on Meta::CPAN
return $abs if $abs = MM->maybe_command($abs);
}
}
}
=head2 $ok | ($ok, $err, $full_buf, $stdout_buff, $stderr_buff) = run( command => COMMAND, [verbose => BOOL, buffer => \$SCALAR] );
C<run> takes 3 arguments:
=over 4
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
add_stopwords($config->{pod_spelling_system}->{stopwords}->@*);
add_stopwords(qw(
Plicease
stdout
stderr
stdin
subref
loopback
username
os
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/00-compile.t view on Meta::CPAN
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/00-compile.t view on Meta::CPAN
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/00-compile.t view on Meta::CPAN
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
view all matches for this distribution
view release on metacpan or search on metacpan
benchmark/test_c.c view on Meta::CPAN
FILE *fp;
int buf_size = 512;
char buf[buf_size];
fp = fopen(filename, "rt");
if (!fp) {
fprintf(stderr, "can't open %s\n", filename);
exit(1);
}
while (fgets(buf, buf_size, fp) != NULL) {
if (len - strlen(*str) < buf_size) {
benchmark/test_c.c view on Meta::CPAN
return 0;
}
static int usage() {
fprintf(stderr, "\n"
"Usage: test_c test\n"
" test_c benchmark\n"
" test_c file\n"
);
return 1;
benchmark/test_c.c view on Meta::CPAN
else if (strcmp(argv[1], "benchmark") == 0)
run_benchmark();
else if (strcmp(argv[1], "file") == 0)
run_file();
else {
fprintf(stderr, "unrecognized commad '%s'. Abort!\n", argv[1]);
return 1;
}
return 0;
}
view all matches for this distribution
view release on metacpan or search on metacpan
inc/Capture/Tiny.pm view on Meta::CPAN
#--------------------------------------------------------------------------#
my %api = (
capture => [1,1,0,0],
capture_stdout => [1,0,0,0],
capture_stderr => [0,1,0,0],
capture_merged => [1,1,1,0],
tee => [1,1,0,1],
tee_stdout => [1,0,0,1],
tee_stderr => [0,1,0,1],
tee_merged => [1,1,1,1],
);
for my $sub ( keys %api ) {
my $args = join q{, }, @{$api{$sub}};
inc/Capture/Tiny.pm view on Meta::CPAN
}
$proxies{stdout} = \*STDOUT;
binmode(STDOUT, ':utf8') if $] >= 5.008;
}
if ( ! defined fileno STDERR ) {
$proxy_count{stderr}++;
if (defined $dup{stderr}) {
_open \*STDERR, ">&=" . fileno($dup{stderr});
# _debug( "# restored proxy STDERR as " . (defined fileno STDERR ? fileno STDERR : 'undef' ) . "\n" );
}
else {
_open \*STDERR, ">" . File::Spec->devnull;
# _debug( "# proxied STDERR as " . (defined fileno STDERR ? fileno STDERR : 'undef' ) . "\n" );
_open $dup{stderr} = IO::Handle->new, ">&=STDERR";
}
$proxies{stderr} = \*STDERR;
binmode(STDERR, ':utf8') if $] >= 5.008;
}
return %proxies;
}
inc/Capture/Tiny.pm view on Meta::CPAN
}
}
sub _copy_std {
my %handles;
for my $h ( qw/stdout stderr stdin/ ) {
next if $h eq 'stdin' && ! $IS_WIN32; # WIN32 hangs on tee without STDIN copied
my $redir = $h eq 'stdin' ? "<&" : ">&";
_open $handles{$h} = IO::Handle->new(), $redir . uc($h); # ">&STDOUT" or "<&STDIN"
}
return \%handles;
inc/Capture/Tiny.pm view on Meta::CPAN
# the output handles (setting up redirection)
sub _open_std {
my ($handles) = @_;
_open \*STDIN, "<&" . fileno $handles->{stdin} if defined $handles->{stdin};
_open \*STDOUT, ">&" . fileno $handles->{stdout} if defined $handles->{stdout};
_open \*STDERR, ">&" . fileno $handles->{stderr} if defined $handles->{stderr};
}
#--------------------------------------------------------------------------#
# private subs
#--------------------------------------------------------------------------#
sub _start_tee {
my ($which, $stash) = @_; # $which is "stdout" or "stderr"
# setup pipes
$stash->{$_}{$which} = IO::Handle->new for qw/tee reader/;
pipe $stash->{reader}{$which}, $stash->{tee}{$which};
# _debug( "# pipe for $which\: " . _name($stash->{tee}{$which}) . " " . fileno( $stash->{tee}{$which} ) . " => " . _name($stash->{reader}{$which}) . " " . fileno( $stash->{reader}{$which}) . "\n" );
select((select($stash->{tee}{$which}), $|=1)[0]); # autoflush
# setup desired redirection for parent and child
$stash->{new}{$which} = $stash->{tee}{$which};
$stash->{child}{$which} = {
stdin => $stash->{reader}{$which},
stdout => $stash->{old}{$which},
stderr => $stash->{capture}{$which},
};
# flag file is used to signal the child is ready
$stash->{flag_files}{$which} = scalar tmpnam();
# execute @cmd as a separate process
if ( $IS_WIN32 ) {
inc/Capture/Tiny.pm view on Meta::CPAN
_fork_exec( $which, $stash );
}
}
sub _fork_exec {
my ($which, $stash) = @_; # $which is "stdout" or "stderr"
my $pid = fork;
if ( not defined $pid ) {
Carp::confess "Couldn't fork(): $!";
}
elsif ($pid == 0) { # child
inc/Capture/Tiny.pm view on Meta::CPAN
# _capture_tee() -- generic main sub for capturing or teeing
#--------------------------------------------------------------------------#
sub _capture_tee {
# _debug( "# starting _capture_tee with (@_)...\n" );
my ($do_stdout, $do_stderr, $do_merge, $do_tee, $code, @opts) = @_;
my %do = ($do_stdout ? (stdout => 1) : (), $do_stderr ? (stderr => 1) : ());
Carp::confess("Custom capture options must be given as key/value pairs\n")
unless @opts % 2 == 0;
my $stash = { capture => { @opts } };
for ( keys %{$stash->{capture}} ) {
my $fh = $stash->{capture}{$_};
inc/Capture/Tiny.pm view on Meta::CPAN
local *CT_ORIG_STDERR = *STDERR;
# find initial layers
my %layers = (
stdin => [PerlIO::get_layers(\*STDIN) ],
stdout => [PerlIO::get_layers(\*STDOUT, output => 1)],
stderr => [PerlIO::get_layers(\*STDERR, output => 1)],
);
# _debug( "# existing layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/;
# get layers from underlying glob of tied filehandles if we can
# (this only works for things that work like Tie::StdHandle)
$layers{stdout} = [PerlIO::get_layers(tied *STDOUT)]
if tied(*STDOUT) && (reftype tied *STDOUT eq 'GLOB');
$layers{stderr} = [PerlIO::get_layers(tied *STDERR)]
if tied(*STDERR) && (reftype tied *STDERR eq 'GLOB');
# _debug( "# tied object corrected layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/;
# bypass scalar filehandles and tied handles
# localize scalar STDIN to get a proxy to pick up FD0, then restore later to CT_ORIG_STDIN
my %localize;
$localize{stdin}++, local(*STDIN)
if grep { $_ eq 'scalar' } @{$layers{stdin}};
$localize{stdout}++, local(*STDOUT)
if $do_stdout && grep { $_ eq 'scalar' } @{$layers{stdout}};
$localize{stderr}++, local(*STDERR)
if ($do_stderr || $do_merge) && grep { $_ eq 'scalar' } @{$layers{stderr}};
$localize{stdin}++, local(*STDIN), _open( \*STDIN, "<&=0")
if tied *STDIN && $] >= 5.008;
$localize{stdout}++, local(*STDOUT), _open( \*STDOUT, ">&=1")
if $do_stdout && tied *STDOUT && $] >= 5.008;
$localize{stderr}++, local(*STDERR), _open( \*STDERR, ">&=2")
if ($do_stderr || $do_merge) && tied *STDERR && $] >= 5.008;
# _debug( "# localized $_\n" ) for keys %localize;
# proxy any closed/localized handles so we don't use fds 0, 1 or 2
my %proxy_std = _proxy_std();
# _debug( "# proxy std: @{ [%proxy_std] }\n" );
# update layers after any proxying
$layers{stdout} = [PerlIO::get_layers(\*STDOUT, output => 1)] if $proxy_std{stdout};
$layers{stderr} = [PerlIO::get_layers(\*STDERR, output => 1)] if $proxy_std{stderr};
# _debug( "# post-proxy layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/;
# store old handles and setup handles for capture
$stash->{old} = _copy_std();
$stash->{new} = { %{$stash->{old}} }; # default to originals
for ( keys %do ) {
$stash->{new}{$_} = ($stash->{capture}{$_} ||= File::Temp->new);
inc/Capture/Tiny.pm view on Meta::CPAN
# _debug("# will capture $_ on " . fileno($stash->{capture}{$_})."\n" );
_start_tee( $_ => $stash ) if $do_tee; # tees may change $stash->{new}
}
_wait_for_tees( $stash ) if $do_tee;
# finalize redirection
$stash->{new}{stderr} = $stash->{new}{stdout} if $do_merge;
# _debug( "# redirecting in parent ...\n" );
_open_std( $stash->{new} );
# execute user provided code
my ($exit_code, $inner_error, $outer_error, @result);
{
local *STDIN = *CT_ORIG_STDIN if $localize{stdin}; # get original, not proxy STDIN
# _debug( "# finalizing layers ...\n" );
_relayer(\*STDOUT, $layers{stdout}) if $do_stdout;
_relayer(\*STDERR, $layers{stderr}) if $do_stderr;
# _debug( "# running code $code ...\n" );
local $@;
eval { @result = $code->(); $inner_error = $@ };
$exit_code = $?; # save this for later
$outer_error = $@; # save this for later
inc/Capture/Tiny.pm view on Meta::CPAN
# _debug( "# restoring filehandles ...\n" );
_open_std( $stash->{old} );
_close( $_ ) for values %{$stash->{old}}; # don't leak fds
# shouldn't need relayering originals, but see rt.perl.org #114404
_relayer(\*STDOUT, $layers{stdout}) if $do_stdout;
_relayer(\*STDERR, $layers{stderr}) if $do_stderr;
_unproxy( %proxy_std );
# _debug( "# killing tee subprocesses ...\n" ) if $do_tee;
_kill_tees( $stash ) if $do_tee;
# return captured output, but shortcut in void context
# unless we have to echo output to tied/scalar handles;
inc/Capture/Tiny.pm view on Meta::CPAN
$got{$_} = _slurp($_, $stash);
# _debug("# slurped " . length($got{$_}) . " bytes from $_\n");
}
print CT_ORIG_STDOUT $got{stdout}
if $do_stdout && $do_tee && $localize{stdout};
print CT_ORIG_STDERR $got{stderr}
if $do_stderr && $do_tee && $localize{stderr};
}
$? = $exit_code;
$@ = $inner_error if $inner_error;
die $outer_error if $outer_error;
# _debug( "# ending _capture_tee with (@_)...\n" );
return unless defined wantarray;
my @return;
push @return, $got{stdout} if $do_stdout;
push @return, $got{stderr} if $do_stderr && ! $do_merge;
push @return, @result;
return wantarray ? @return : $return[0];
}
1;
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
add_stopwords(@{ $config->{pod_spelling_system}->{stopwords} });
add_stopwords(qw(
Plicease
stdout
stderr
stdin
subref
loopback
username
os
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
add_stopwords(@{ $config->{pod_spelling_system}->{stopwords} });
add_stopwords(qw(
Plicease
stdout
stderr
stdin
subref
loopback
username
os
view all matches for this distribution
view release on metacpan or search on metacpan
script/makepatch view on Meta::CPAN
If set, the program name and version is reported.
=item B<->[B<no>]B<verbose>
This is set by default, making B<makepatch> display information concerning
its activity to I<stderr>.
=item B<->[B<no>]B<quiet>
The opposite of B<-verbose>. If set, this instructs B<makepatch> to
suppress the display of activity information.
view all matches for this distribution
view release on metacpan or search on metacpan
sub Cmd {
my $cmd = shift;
my $outfile = shift;
defined $outfile or $outfile = "";
# create arrays into which stdout / stderr will be read
# if second argument is arrayref, store stdout in that array, else create private anonymous array
my $stdout = [];
if ((ref $outfile) eq 'ARRAY') {
$stdout = $outfile;
$outfile = ""; # so we'll create a temporary file
}
my $stderr = [];
my $stdout_tmp = undef; # create temporary files for capturing stdout and stderr
my $stderr_tmp = new CWB::TempFile "CWB-Shell-Cmd-STDERR";
my $stdout_file = $outfile;
if (not $outfile) {
$stdout_tmp = new CWB::TempFile "CWB-Shell-Cmd-STDOUT";
$stdout_tmp->finish; # now we're allowed to access the file directly
$stdout_file = $stdout_tmp->name;
}
$stderr_tmp->finish;
my $stderr_file = $stderr_tmp->name;
my $status = system "($cmd) 1>$stdout_file 2>$stderr_file";
my $syscode = $status & 0xff;
my $exitval = $status >> 8;
my $fh = CWB::OpenFile $stderr_file;
@$stderr = <$fh>;
map {chomp;} @$stderr;
$fh->close;
if ($outfile) {
@$stdout = (); # don't check STDOUT if caller wants it in file
}
else {
}
$current_cmd = $cmd; # Error() may want to report the command that failed
$return_status = 0; # error level will be increased (but not decreased) by Error() function
Error 6, "System error: $!", @$stderr
if $syscode != 0;
Error 5, "Non-zero exit value $exitval.", @$stderr
if $exitval != 0;
Error 5, "Error message on stderr:", @$stderr
if grep { /error|fail|abnormal|abort/i } @$stderr;
Error 3, "Warning on stderr:", @$stderr
if grep { /warn|problem/i } @$stderr;
Error 2, "Stderr output:", @$stderr
if @$stderr;
Error 1, "Error message on stdout:", @$stdout
if grep { /error|fail|abnormal|abort/i } @$stdout;
# return highest error status set by one of the previous commands
return $return_status;
view all matches for this distribution
view release on metacpan or search on metacpan
return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;
}
BIO *dup_bio_err(int format)
{
BIO *b = BIO_new_fp(stderr,
BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));
return b;
}
#endif
pkey = _load_pkey(pk, PEM_read_bio_PrivateKey);
cert_chain = _load_cert_chain(cert_chain_pem, PEM_X509_INFO_read_bio);
p12 = PKCS12_create(pass, name, pkey, sk_X509_shift(cert_chain), cert_chain, 0, 0, 0, 0, 0);
if (!p12) {
ERR_print_errors_fp(stderr);
croak("Error creating PKCS#12 structure\n");
}
if (!(fp = fopen(file, "wb"))) {
ERR_print_errors_fp(stderr);
croak("Error opening file %s\n", file);
}
i2d_PKCS12_fp(fp, p12);
PKCS12_free(p12);
pkey = _load_pkey(pk, PEM_read_bio_PrivateKey);
cert_chain = _load_cert_chain(cert_chain_pem, PEM_X509_INFO_read_bio);
p12 = PKCS12_create(pass, name, pkey, sk_X509_shift(cert_chain), cert_chain, 0, 0, 0, 0, 0);
if (!p12) {
ERR_print_errors_fp(stderr);
croak("Error creating PKCS#12 structure\n");
}
CHECK_OPEN_SSL(bio = BIO_new(BIO_s_mem()));
i2d_PKCS12_bio(bio, p12);
view all matches for this distribution
view release on metacpan or search on metacpan
t/00-compile.t view on Meta::CPAN
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
if (@_warnings)
{
view all matches for this distribution
view release on metacpan or search on metacpan
t/original/warns.t view on Meta::CPAN
use Test::More tests => 6;
$^W = 0; # No warnings
{
local *STDERR;
my $stderr_seen = "";
open STDERR, '>', \$stderr_seen;
$str = Digest::MD5->md5_hex("foo");
is($stderr_seen,'','No warnings');
}
{
$^W = 1; # magic turn on warnings
local *STDERR;
my $stderr_seen = "";
open STDERR, '>', \$stderr_seen;
$str = Digest::MD5->md5_hex("foo");
like($stderr_seen,qr/Digest::MD5::md5_hex function probably called as class method/,
'Lexical warning passed to XSUB');
}
{
$^W = 0; # No warnings
local *STDERR;
my $stderr_seen = "";
open STDERR, '>', \$stderr_seen;
$str = Digest::MD5->md5_hex("foo");
is($stderr_seen,'','No warnings again');
}
{
use warnings;
local *STDERR;
my $stderr_seen = "";
open STDERR, '>', \$stderr_seen;
$str = Digest::MD5->md5_hex("foo");
like($stderr_seen,qr/Digest::MD5::md5_hex function probably called as class method/,
'use warnings passed to XSUB');
}
{
use strict;
$^W = 0; # No warnings
local *STDERR;
my $stderr_seen = "";
open STDERR, '>', \$stderr_seen;
my $str = Digest::MD5->md5_hex("foo");
is($stderr_seen,'','No warnings and strict');
}
{
use strict;
use warnings;
local *STDERR;
my $stderr_seen = "";
open STDERR, '>', \$stderr_seen;
my $str = Digest::MD5->md5_hex("foo");
like($stderr_seen, qr/Digest::MD5::md5_hex function probably called as class method/,
'use warnings passed to XSUB while use strict');
}
view all matches for this distribution
view release on metacpan or search on metacpan
t/01_use.t
t/1.t
t/2.t
t/3.t
t/4.t
t/swallow_stderr.inc
t/test_glib-2.0.pc
t/test_non_numeric.pc
t/test_short.pc
xt/author/eol.t
xt/author/no_tabs.t
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
add_stopwords(@{ $config->{pod_spelling_system}->{stopwords} });
add_stopwords(qw(
Plicease
stdout
stderr
stdin
subref
loopback
username
os
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
add_stopwords(@{ $config->{pod_spelling_system}->{stopwords} });
add_stopwords(qw(
Plicease
stdout
stderr
stdin
subref
loopback
username
os
view all matches for this distribution
view release on metacpan or search on metacpan
inc/TestML/Library/Standard.pm view on Meta::CPAN
# $command = $command->value;
# chomp($command);
# my $sub = sub {
# system($command);
# };
# my ($stdout, $stderr) = Capture::Tiny::capture($sub);
# $self->runtime->function->setvar('_Stdout', $stdout);
# $self->runtime->function->setvar('_Stderr', $stderr);
# return str('');
# }
# sub RmPath {
# require File::Path;
view all matches for this distribution
view release on metacpan or search on metacpan
inc/Capture/Tiny.pm view on Meta::CPAN
#--------------------------------------------------------------------------#
my %api = (
capture => [1,1,0,0],
capture_stdout => [1,0,0,0],
capture_stderr => [0,1,0,0],
capture_merged => [1,1,1,0],
tee => [1,1,0,1],
tee_stdout => [1,0,0,1],
tee_stderr => [0,1,0,1],
tee_merged => [1,1,1,1],
);
for my $sub ( keys %api ) {
my $args = join q{, }, @{$api{$sub}};
inc/Capture/Tiny.pm view on Meta::CPAN
}
$proxies{stdout} = \*STDOUT;
binmode(STDOUT, ':utf8') if $] >= 5.008;
}
if ( ! defined fileno STDERR ) {
$proxy_count{stderr}++;
if (defined $dup{stderr}) {
_open \*STDERR, ">&=" . fileno($dup{stderr});
# _debug( "# restored proxy STDERR as " . (defined fileno STDERR ? fileno STDERR : 'undef' ) . "\n" );
}
else {
_open \*STDERR, ">" . File::Spec->devnull;
# _debug( "# proxied STDERR as " . (defined fileno STDERR ? fileno STDERR : 'undef' ) . "\n" );
_open $dup{stderr} = IO::Handle->new, ">&=STDERR";
}
$proxies{stderr} = \*STDERR;
binmode(STDERR, ':utf8') if $] >= 5.008;
}
return %proxies;
}
inc/Capture/Tiny.pm view on Meta::CPAN
}
}
sub _copy_std {
my %handles;
for my $h ( qw/stdout stderr stdin/ ) {
next if $h eq 'stdin' && ! $IS_WIN32; # WIN32 hangs on tee without STDIN copied
my $redir = $h eq 'stdin' ? "<&" : ">&";
_open $handles{$h} = IO::Handle->new(), $redir . uc($h); # ">&STDOUT" or "<&STDIN"
}
return \%handles;
inc/Capture/Tiny.pm view on Meta::CPAN
# the output handles (setting up redirection)
sub _open_std {
my ($handles) = @_;
_open \*STDIN, "<&" . fileno $handles->{stdin} if defined $handles->{stdin};
_open \*STDOUT, ">&" . fileno $handles->{stdout} if defined $handles->{stdout};
_open \*STDERR, ">&" . fileno $handles->{stderr} if defined $handles->{stderr};
}
#--------------------------------------------------------------------------#
# private subs
#--------------------------------------------------------------------------#
sub _start_tee {
my ($which, $stash) = @_; # $which is "stdout" or "stderr"
# setup pipes
$stash->{$_}{$which} = IO::Handle->new for qw/tee reader/;
pipe $stash->{reader}{$which}, $stash->{tee}{$which};
# _debug( "# pipe for $which\: " . _name($stash->{tee}{$which}) . " " . fileno( $stash->{tee}{$which} ) . " => " . _name($stash->{reader}{$which}) . " " . fileno( $stash->{reader}{$which}) . "\n" );
select((select($stash->{tee}{$which}), $|=1)[0]); # autoflush
# setup desired redirection for parent and child
$stash->{new}{$which} = $stash->{tee}{$which};
$stash->{child}{$which} = {
stdin => $stash->{reader}{$which},
stdout => $stash->{old}{$which},
stderr => $stash->{capture}{$which},
};
# flag file is used to signal the child is ready
$stash->{flag_files}{$which} = scalar tmpnam();
# execute @cmd as a separate process
if ( $IS_WIN32 ) {
inc/Capture/Tiny.pm view on Meta::CPAN
_fork_exec( $which, $stash );
}
}
sub _fork_exec {
my ($which, $stash) = @_; # $which is "stdout" or "stderr"
my $pid = fork;
if ( not defined $pid ) {
Carp::confess "Couldn't fork(): $!";
}
elsif ($pid == 0) { # child
inc/Capture/Tiny.pm view on Meta::CPAN
# _capture_tee() -- generic main sub for capturing or teeing
#--------------------------------------------------------------------------#
sub _capture_tee {
# _debug( "# starting _capture_tee with (@_)...\n" );
my ($do_stdout, $do_stderr, $do_merge, $do_tee, $code, @opts) = @_;
my %do = ($do_stdout ? (stdout => 1) : (), $do_stderr ? (stderr => 1) : ());
Carp::confess("Custom capture options must be given as key/value pairs\n")
unless @opts % 2 == 0;
my $stash = { capture => { @opts } };
for ( keys %{$stash->{capture}} ) {
my $fh = $stash->{capture}{$_};
inc/Capture/Tiny.pm view on Meta::CPAN
local *CT_ORIG_STDERR = *STDERR;
# find initial layers
my %layers = (
stdin => [PerlIO::get_layers(\*STDIN) ],
stdout => [PerlIO::get_layers(\*STDOUT, output => 1)],
stderr => [PerlIO::get_layers(\*STDERR, output => 1)],
);
# _debug( "# existing layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/;
# get layers from underlying glob of tied filehandles if we can
# (this only works for things that work like Tie::StdHandle)
$layers{stdout} = [PerlIO::get_layers(tied *STDOUT)]
if tied(*STDOUT) && (reftype tied *STDOUT eq 'GLOB');
$layers{stderr} = [PerlIO::get_layers(tied *STDERR)]
if tied(*STDERR) && (reftype tied *STDERR eq 'GLOB');
# _debug( "# tied object corrected layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/;
# bypass scalar filehandles and tied handles
# localize scalar STDIN to get a proxy to pick up FD0, then restore later to CT_ORIG_STDIN
my %localize;
$localize{stdin}++, local(*STDIN)
if grep { $_ eq 'scalar' } @{$layers{stdin}};
$localize{stdout}++, local(*STDOUT)
if $do_stdout && grep { $_ eq 'scalar' } @{$layers{stdout}};
$localize{stderr}++, local(*STDERR)
if ($do_stderr || $do_merge) && grep { $_ eq 'scalar' } @{$layers{stderr}};
$localize{stdin}++, local(*STDIN), _open( \*STDIN, "<&=0")
if tied *STDIN && $] >= 5.008;
$localize{stdout}++, local(*STDOUT), _open( \*STDOUT, ">&=1")
if $do_stdout && tied *STDOUT && $] >= 5.008;
$localize{stderr}++, local(*STDERR), _open( \*STDERR, ">&=2")
if ($do_stderr || $do_merge) && tied *STDERR && $] >= 5.008;
# _debug( "# localized $_\n" ) for keys %localize;
# proxy any closed/localized handles so we don't use fds 0, 1 or 2
my %proxy_std = _proxy_std();
# _debug( "# proxy std: @{ [%proxy_std] }\n" );
# update layers after any proxying
$layers{stdout} = [PerlIO::get_layers(\*STDOUT, output => 1)] if $proxy_std{stdout};
$layers{stderr} = [PerlIO::get_layers(\*STDERR, output => 1)] if $proxy_std{stderr};
# _debug( "# post-proxy layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/;
# store old handles and setup handles for capture
$stash->{old} = _copy_std();
$stash->{new} = { %{$stash->{old}} }; # default to originals
for ( keys %do ) {
$stash->{new}{$_} = ($stash->{capture}{$_} ||= File::Temp->new);
inc/Capture/Tiny.pm view on Meta::CPAN
# _debug("# will capture $_ on " . fileno($stash->{capture}{$_})."\n" );
_start_tee( $_ => $stash ) if $do_tee; # tees may change $stash->{new}
}
_wait_for_tees( $stash ) if $do_tee;
# finalize redirection
$stash->{new}{stderr} = $stash->{new}{stdout} if $do_merge;
# _debug( "# redirecting in parent ...\n" );
_open_std( $stash->{new} );
# execute user provided code
my ($exit_code, $inner_error, $outer_error, @result);
{
local *STDIN = *CT_ORIG_STDIN if $localize{stdin}; # get original, not proxy STDIN
# _debug( "# finalizing layers ...\n" );
_relayer(\*STDOUT, $layers{stdout}) if $do_stdout;
_relayer(\*STDERR, $layers{stderr}) if $do_stderr;
# _debug( "# running code $code ...\n" );
local $@;
eval { @result = $code->(); $inner_error = $@ };
$exit_code = $?; # save this for later
$outer_error = $@; # save this for later
inc/Capture/Tiny.pm view on Meta::CPAN
# _debug( "# restoring filehandles ...\n" );
_open_std( $stash->{old} );
_close( $_ ) for values %{$stash->{old}}; # don't leak fds
# shouldn't need relayering originals, but see rt.perl.org #114404
_relayer(\*STDOUT, $layers{stdout}) if $do_stdout;
_relayer(\*STDERR, $layers{stderr}) if $do_stderr;
_unproxy( %proxy_std );
# _debug( "# killing tee subprocesses ...\n" ) if $do_tee;
_kill_tees( $stash ) if $do_tee;
# return captured output, but shortcut in void context
# unless we have to echo output to tied/scalar handles;
inc/Capture/Tiny.pm view on Meta::CPAN
$got{$_} = _slurp($_, $stash);
# _debug("# slurped " . length($got{$_}) . " bytes from $_\n");
}
print CT_ORIG_STDOUT $got{stdout}
if $do_stdout && $do_tee && $localize{stdout};
print CT_ORIG_STDERR $got{stderr}
if $do_stderr && $do_tee && $localize{stderr};
}
$? = $exit_code;
$@ = $inner_error if $inner_error;
die $outer_error if $outer_error;
# _debug( "# ending _capture_tee with (@_)...\n" );
return unless defined wantarray;
my @return;
push @return, $got{stdout} if $do_stdout;
push @return, $got{stderr} if $do_stderr && ! $do_merge;
push @return, @result;
return wantarray ? @return : $return[0];
}
1;
view all matches for this distribution
view release on metacpan or search on metacpan
xt/author/pod_spelling_system.t view on Meta::CPAN
add_stopwords(@{ $config->{pod_spelling_system}->{stopwords} });
add_stopwords(qw(
Plicease
stdout
stderr
stdin
subref
loopback
username
os
view all matches for this distribution
view release on metacpan or search on metacpan
t/00-compile.t view on Meta::CPAN
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
view all matches for this distribution
view release on metacpan or search on metacpan
BabelFish.pm view on Meta::CPAN
}
eval <<'REDIRECT_END';
use IO::Redirect;
$ior = IO::Redirect->new();
$ior->redirect_stdout_stderr(\$cpan);
REDIRECT_END
my $mod = CPAN::Shell->expand('Module', 'AltaVista::BabelFish');
if(defined $mod) {
if($VERSION eq $mod->cpan_version) {
if(ref $ior) {
$ior->un_redirect_stdout_stderr();
}
return 1;
}
else {
$errstr{ $ident } = "Installed Version: $VERSION\nLatest "
BabelFish.pm view on Meta::CPAN
if ref $ior;
$errstr{ $ident } = "Undefined CPAN Object." if !ref $ior;
}
if(ref $ior) {
$ior->un_redirect_stdout_stderr();
}
return;
}
view all matches for this distribution
view release on metacpan or search on metacpan
PerlIO_read||5.007003|
PerlIO_seek||5.007003|
PerlIO_set_cnt||5.007003|
PerlIO_set_ptrcnt||5.007003|
PerlIO_setlinebuf||5.007003|
PerlIO_stderr||5.007003|
PerlIO_stdin||5.007003|
PerlIO_stdout||5.007003|
PerlIO_tell||5.007003|
PerlIO_unread||5.007003|
PerlIO_write||5.007003|
warner|5.006000|5.004000|pv
warn|||v
watch|||
whichsig|||
write_no_mem|||
write_to_stderr|||
xmldump_all|||
xmldump_attr|||
xmldump_eval|||
xmldump_form|||
xmldump_indent|||v
view all matches for this distribution
view release on metacpan or search on metacpan
- Correction in the TermTagging : language switch was well
taken into account
- Correction in the management of the ".proc_id" file
- correction in the computing of the xml rendering time
(the variable is set to zero ;-)
- stderr when NLP tools are called, is redirected in a log file
- addition of a variable DEBUG defining a debug mode (temporary
files are not removed)
- alvis-nlp-standalone can read a file given in argument or on
the STDIN stream
- Documentation of the modules and scripts are gathered at the
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Alvis/Logger.pm view on Meta::CPAN
# Create a new logger object. Options that may be specified include:
# level [default 0]: only emit messages with priority less than
# or equal to this (so that the default behaviour is to
# be silent except for priority-zero messages, which are
# really error messages).
# stream [stderr]: where to write messages
#
sub new {
my $class = shift();
#warn("new($class): \@_ = ", join(", ", map { "'$_'" } @_), "\n");
my %options = ( level => 0, stream => \*STDERR, @_ );
view all matches for this distribution
view release on metacpan or search on metacpan
bin/run_QF.pl view on Meta::CPAN
B<--testquery> Transform queries and return response without forwarding query to a real SRU server.
B<--verbose> Some additional trace data provided.
This is a simple SRU query filter built using HTTP::Daemon. All configuration data is read from the ALVIS configuration file at <AlvisDir>/alvis.cnf. Error messages and a simple URL trail go to stderr. The linguistic resources used by
Alvis::Query filter are located in <AlvisDir>/resources.
It is intended to be copied and modified for any application.
=head1 CONFIGURATION
view all matches for this distribution
view release on metacpan or search on metacpan
t/00-compile.t view on Meta::CPAN
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { require blib; blib->VERSION('1.01') };
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Amazon/MWS/Uploader.pm view on Meta::CPAN
{ success => 1 },
{
feed_id => $feed_id,
shop_id => $self->_unique_shop_id,
}));
# if we have a success, print the warnings on the stderr.
# if we have a failure, the warnings will just confuse us.
if ($type eq 'order_ack') {
# flip the confirmation bit
$self->_exe_query($self->sqla->update(amazon_mws_orders => { confirmed => 1 },
view all matches for this distribution