in reply to [SOLVED] Capturing errors from 3-arg pipe open in ActivePerl 5.020
From the same document a few paragraphs up from the General Examples section:
Open returns nonzero on success, the undefined value otherwise. If the open involved a pipe, the return value happens to be the pid of the subprocess.
Even if the command isn't on your system the pipe is opening a subprocess and returning the pid. Here's what I see on Windows 8.
use warnings; use strict; print "here it goes...\n"; my $return_val = open(my $article, "-|", "caesar <article"); # or die "Can't start caesar: $!"; print "tried it and got [$return_val]\n";
Updatec:\usr\pm>openprog.pl > openprog.txt 2>&1 here it goes... The system cannot find the file specified. tried it and got [14048]
use warnings; use strict; use Win32::Process::List; $!=0; print "here it goes...<$!>\n"; my $return_val = open(my $article, "-|", "caesar <article"); # or die "Can't start caesar: $!"; print "tried it and got [$return_val] <$!>\n"; print "="x75,"\n"; my %list = Win32::Process::List->new()->GetProcesses(); #return +s the hashes with PID and process name foreach my $key ( keys %list ) { # $list{$key} is now the process name and $key is the PID print sprintf("%30s has PID %15s", $list{$key}, $key) . "\n" if $k +ey == $return_val; } print "="x75,"\n";
here it goes...<> The system cannot find the file specified. tried it and got [8664] <Inappropriate I/O control operation> ====================================================================== +===== cmd.exe has PID 8664 ====================================================================== +=====
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Capturing errors from 3-arg pipe open in ActivePerl 5.020
by ateague (Monk) on Nov 16, 2015 at 17:50 UTC | |
by Lotus1 (Vicar) on Nov 16, 2015 at 18:53 UTC |