in reply to Problems with open

It will die if you have 5.6.0 or later.

What is happening is this: the open will open a pipe, fork, and the child will exec "garbage". On perls older than 5.6.0, open will return the pid - that is, it will return true if the fork succeeded.

Since 5.6.0, if you pipe open a simple program (one which doesn't require the shell to resolve special characters), and said program doesn't exist, the handling is special cased and the open itself will fail.

open my $fh => "| garbage *" or die;
will not die, because Perl will fork and exec a shell (which will succeed), asking the shell to execute garbage * (which can't be done because "garbage" doesn't exist).

Abigail

Replies are listed 'Best First'.
Re: Re: Problems with open
by skerr1 (Sexton) on Jul 24, 2002 at 15:07 UTC
    Thanks a lot! So it looks like I need a work around for this. I am using Perl 5.005_02. Any ideas?

    -Shannon
      Well, you could upgrade.... ;-).

      If you know the command after the pipe is going to be simple (just letters, digits and whitespace), you could test whether the first word exists somewhere in the current path and is executable. Or peek in the source of a modern perl and see how's it dealt with and mimic that.

      But note that even recent perls only handle cases that don't involve the shell.

      Abigail

        Testing whether it exists in the current path sounds like a great idea. I could do this in several cases. The problem occurs when it does exist and what is passed to it (via print) happens to be incorrect (i.e. if you were expecting parameters and they were in the wrong format).

        Could you give me a little direction of the checking if the first word exists somewhere in the current path. I can think of a difficult way of doing it, is there any simple or built-in method for checking if a word is in the PATH?

        I really appreciate your help. Thanks!

        -Shannon