mwhiting has asked for the wisdom of the Perl Monks concerning the following question:

Hi - I am getting a bad file descriptor when trying to open a executable program using the pipe symbol, with the following code:
open (MAIL, "|$mailProg") || die "Can't create pipe to $mailProg!\n";

What would create that message? The file is there, we can run it from the browser http line, so it is accessible via the web. I saw a couple of usegroups on the net comment on it being a user group/permissions issue in NT. This is NT 2003, and I think that might be significant. The file is set to be executable in NT 2003.

Thanks monks!

Replies are listed 'Best First'.
Re: Bad File Descriptor
by jettero (Monsignor) on Oct 23, 2007 at 18:07 UTC

    You might try to get a slightly more meaningful error message like this:

    open (MAIL, "|$mailProg") || die "Can't create pipe to $mailProg: $!";

    $! should contain the error message as a string and die will announce more about the location of the error without the "\n" on the end. The documentation for both open and perlvar talk about $!.

    Also, if you felt like doing things in the exceedingly modern perl-cool way, you'd write it like this:

    open my $mailer, "|-", $mail_prog or die "couldn't open pipe to $mail_ +prog: $!";

    Then $mailer will close itself when it goes out of scope and you don't pollute your package namespace with all-caps globs.

    -Paul

      Yes - I did use the $! afterwards - sorry that wasn't in the code there. That's how I found out it was a "Bad File Descriptor" error message. Until then I didn't have anything. I saw the "|-" usage when I was looking into this problem too - maybe I'll change it to that. Any thoughts about the cause of the error message?

      Michael

        "Bad file descriptor" doesn't make sense as a failure reason for the code you posted. So I suspect your problem is something else. Please cut and paste some exact code that demonstrates the problem and the exact output that it produces.

        - tye        

Re: Bad File Descriptor
by BrowserUk (Patriarch) on Oct 23, 2007 at 21:24 UTC

    The "Bad file descriptor" error in $! is almost certainly a red-herring left over from some internal processing of no consequence to your code. Try printing $^E and see what that tells you?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Bad File Descriptor
by aquarium (Curate) on Oct 23, 2007 at 23:07 UTC
    if you have a choice between IIS and Apache...use Apache. IIS has been progressively locked down more and more...processes started through IIS typically have problems opening/writing files and using pipes
    the hardest line to type correctly is: stty erase ^H