in reply to Writing to descriptor 3

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 --

Replies are listed 'Best First'.
(tye)Re2: Writing to descriptor 3
by tye (Sage) on Mar 06, 2001 at 22:12 UTC

    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 --

        Ah, the program requires you to arrange for it to be able to read from FD 3... hmm, I think that is probably a bad design on their part, but...

        I don't have time to write a solution at the moment. I guess you are supposed to create a pipe(), fork(), have the child close FD 3 and then use dup2() to make FD 3 the read end of the pipe, and finally exec() 'checkpassword'.

        You should be able to do this in Perl, but it may be a little tricky. [I don't think Perl gives the script writer full access to dup2() but you can still fake Perl into closing FD 3 and then just dup() the read end of the pipe with open(ANY,"<&READER")]

        Note also that to get the program to read from FD 3 does not require that you be writing to FD 3 (in case their documentation needs to be updated).

                - tye (but my friends call me "Tye")