F
fishfry
#!/usr/bin/perl
use strict;
# 1. The open() call returns false.
my $x = open(XX, "| junk");
print "x = $x\n";
# 2. The open() call returns true.
my $y = open(YY, "| junk > foozle");
print "y = $y\n";
When the above code is run (on a Unix system), $x has a value of 0, and
$y has a nonzero value.
junk is a non-existent executable. It's correct for the open() to fail,
since the process creation failed.
However, adding an output redirect causes open() to return a nonzero
value.
This is causing me a problem, since I need to know if the process
creation failed.
Any explanation for why the second example returns true? And perhaps an
alternate way to do the same thing so I can find out if the process
creation fails?
use strict;
# 1. The open() call returns false.
my $x = open(XX, "| junk");
print "x = $x\n";
# 2. The open() call returns true.
my $y = open(YY, "| junk > foozle");
print "y = $y\n";
When the above code is run (on a Unix system), $x has a value of 0, and
$y has a nonzero value.
junk is a non-existent executable. It's correct for the open() to fail,
since the process creation failed.
However, adding an output redirect causes open() to return a nonzero
value.
This is causing me a problem, since I need to know if the process
creation failed.
Any explanation for why the second example returns true? And perhaps an
alternate way to do the same thing so I can find out if the process
creation fails?