Re: Testing Success of Opening Pipe in Windows

"$Bill Luebkert" <[email protected]> Sun, 12 Aug 2012 17:35:22 -0700
Newsgroups gmane.comp.lang.perl.active-perl
Message-ID <[email protected]>
On 8/12/2012 13:48, Edwards, Mark (CXO) wrote:
> The typical test for open is ...
>
> open(HANDLE, "something _/to/_open") or die "Open failed, $!";
>
> That works on Windows for a file but not a pipe.
>
> $status=open(PIPE, "hostname |");
>
> This works and I can read from the pipe but $status is always non-zero so I don't know whether it succeeds or fails.  Even testing for $! or $? doesn't work.  $? is always -1 and $! is always " Inappropriate I/O control operation".  This works as expected on Unix be how do I test for success or failure of opening the pipe?

Any reason why not to just use a backtick version:

my $host = `hostname`;
chomp $host;
print "OS Error: '$!'\n";
print "Child Error: '$?'\n";
print "^E : '$^E'\n";
print "Host Name: '$host'\n";

OS Error: ''
Child Error: '0'
^E : 'The pipe has been ended'
Host Name: 'MYHOST'

or

use IO::Pipe;

my $pipe = new IO::Pipe;
$pipe->reader('hostname');
my $host;
{ local $/ = undef; $host = <$pipe> }
my $status = $pipe->close;
print "OS Error: '$!'\n";
print "Child Error: '$?'\n";
print "^E : '$^E'\n";
print "Status: $status\n";
print "Host Name: $host\n";
print "\n";

OS Error: ''
Child Error: '0'
^E : 'The pipe has been ended'
Status: 1
Host Name: MYHOST

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs