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

Greetings all,
I'm trying to use a programme (qmail's checkpassword), which requires you to pass data to it via descriptor 3.
Now, alright, I'll admit - I don't even know what descriptor 3 is, definately sounds oldworld UNIX to me, but none the less -- can anyone give me a heads up on how to open descriptor 3 to be written to?

Thanks all,
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Replies are listed 'Best First'.
(Zigster) Re: Writing to descriptor 3
by zigster (Hermit) on Mar 06, 2001 at 21:45 UTC
    look a the documentation for open
    If you specify '<&=N', where N is a number, then Perl will 
    do an equivalent of C's fdopen() of that file descriptor; 
    this is more parsimonious of file descriptors. For example:
    
        open(FILEHANDLE, "<&=$fd")
    
    So
    open(FHAND,'>&=3') || die ("Dead as a dead thing");
    Should open a file handle to descriptor 3. If you really want more info on what exactly descriptors are then follow up, this should get you on your way.

    Update

    Changed < for > in the open as tye points out the original question was for writing not reading .. *dowt*
    --

    Zigster

      Just what I was typing... Except he said "for writing" so replace the "<" with a ">".

              - tye (but my friends call me "Tye")
Re: Writing to descriptor 3
by JPaul (Hermit) on Mar 06, 2001 at 22:07 UTC
    Alas, this does not work.
    Taking your exact line - open(FHAND, ">&=3") || die...
    Always die()s - "Bad File Descriptor"

    JP -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

      For this program to have this requirement, it must be executing your script in such a way that the script inherits an open file descriptor 3.

      If you test your script outside of this environment, then you will get the error you describe above. If you are testing inside the environment and get that error, then there is a good chance that the problem is with the other program.

              - tye (but my friends call me "Tye")
        Alright. I get it.
        Actually, I'm lying. I understand what you mean, but I guess I'm at a loss on how to make it do what I want.

        When checkpassword is run, it checks fd 3 (Which, I believe, it supposed to be somehow already open - since the first line is a read()) and then returns an exit status depending on its result.
        My script is the front-end to checkpassword, I need to open fd 3, write the username/pw pair to fd 3, and then run 'checkpassword' and watch its exit stat.

        Any clues?

        JP
        -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

A reply falls below the community's threshold of quality. You may see it by logging in.