------------------------------------------------ On Tue, 31 Dec 2002 15:31:47 -0500, "Kipp, James" <[EMAIL PROTECTED]> wrote:
> > > > I am making a call to gpg on the command line, a couple of > > the parameters that gpg will accept are file descriptor > > numbers that it then writes to, and I would like to capture > > that output and then read from it. > > > > I have successfully made it read directly from a file on the > > local file system like so: > > > > my $pass_fh = IO::File->new('/path/to/localfile'); > > fcntl $pass_fh, F_SETFD, 0; # don't close over exec > > my $pass_fd = $pass_fh->fileno(); # get the file descriptor number > > > > and then calling gpg on the command line like so: > > > > gpg [other options here, etc.] --passphrase-fd $pass_fd [etc.] > > > > Which works very well. And I can successfully create a new > > file handle, > > > > my $logger_fh = IO::Handle->new(); > > > > And then presumably could use the same methods as above, but > > the file handle has to be open to determine its number and > > then to pass the file descriptor to the command line. Which I > > determined is what fdopen is for, so now to my question(s) > > (finally, sorry about that) how do I determine what the FD > > (file descriptor number) should be that I pass to fdopen? Is > > this an arbitrary number (not 0,1,2), can I have the system > > suggest a number? If the program were to choose the same > > number in different forks would it matter? Is there a better > > more appropriate way of handling all of this? (Besides using > > one of the GPG modules from CPAN, which I would absolutely > > love, but after spending a number of days checking them out, > > each one has one or more quirks which doesn't allow it to > > work in our app.) > > I am not sure if this helps or if you already knew this, but the camel book > has section on it in chapter 16, under the 'Passing File' Handles section. I had seen that and been through it a couple times, for another issue, but went through it again, can't hurt right ;-), but all of the examples seem to open an already existing file, creating a file, or using a handle as part of a pipe. It did give me the idea of trying to open a new file handle with the "-|" syntax to open but that just errored, and left $! blank which is odd to me... > also the fdopen manpages states that you obtain an existing FD from open, > fcntl..... Right, but I am not sure how to get an existing FD without attaching it to an actual normal file through an open call. the fdopen essentially attaches a separate handle to the existing file descriptor, but I need to know how to generate a file descriptor without attaching it to a file on the filesytem, if this can be done at all, at least at Perl's high level, as this is seemingly done by 'pipe'. > So i assume the open method in IO::File is really the open2 > system call. I believe IO::File is just a sub class of IO::Handle, and fdopen just wraps a regular open call. > Also are you loading the Fcntl module in the program so you get all of the > constants from cntl.h? Yes, that is how I am setting the filehandle to stay open through the exec (system in my case). But I am not familar with what that gets me as I don't make much of a C programmer (yet hopefully ;-)), any suggestions on what I can use from it for this problem? > Don't know if this helps you at all, but thought i would give throw it out > there. > Thanks, discussion can't ever hurt thats for sure. > > ps.. I can send you the HTML section on this if you don't have it handy. > Got it. Don't leave home without it. thanks again for any help, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]