The ^E is the same whether the pipe opens or not.  Same problems with 
IPC::Open2 and IO::Pipe. 

Back ticks usually work but in this case the program may return 10's or 100's 
of MB and I'm short on resources.  I found a work around by doing this.

open(PIPE, "hostname |");
die "Pipe didn't open or it returned nothing" if (eof(PIPE));

-----Original Message-----
From: $Bill Luebkert [mailto:dbec...@roadrunner.com] 
Sent: Sunday, August 12, 2012 6:35 PM
To: Edwards, Mark (CXO)
Cc: activeperl@listserv.activestate.com
Subject: Re: Testing Success of Opening Pipe in Windows

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
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to