开发者

what happens if open fails?

I came across the following code:

my $pid = open (my $han开发者_JAVA技巧dler, "-|");
unless ($pid) 
{
    #child stuff
    exec $command;
}
else
{
    #parent stuff
}

what would happen if the implicit fork fails? will the command be executed anyway?


Yes the command will be executed, unless the code uses something like autodie.

open($fh, '-|') returns undef on failure, which is false, so the (unforked) process would exec the command (and thus terminate itself).

(On an unrelated note, I, and many other programmers, feel that unless ... else ... is bad style, but it is valid Perl.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜