in reply to Re^2: using a pipe
in thread using a pipe
OK, so if I understand correctly,
The first thing to notice is that the cat might be unnecesary. In other words,
should have the same effect ascat file | gpg
gpg <file
but the second is simpler and eliminates an unnecesary pipeline stage. In either case the contents of file becomes the standard input for gpg. The only reason it would matter is if for some reason gpg really insisted that the passphrase-fd be a pipe.
If that will do, then you may be able to reduce the whole thing down to something as simple as this:
# Open the file open(FILE, "<file") || die; # Run gpg # Notice that we are not going to bother to try to # make the file become stdin to gpg. We're just going # to tell gpg which file descriptor it's already # accessible as. system("gpg", "--passphrase-fd=" . fileno(FILE), "--decrypt", "--output", "cleartext-filename", "ciphertext-filename"); close FILE;
That's the true intent of gpg's passphrase-fd option: to give it a file descriptor for some other file besides the three stdio ones.
You may notice that this can be improved a little bit because, in fact, the parent process (perl script) does not have to open the file at all, it only needs to be opened in the child process (the one that execs gpg). You can easily make that change to the above example but you have to play with fork, exec and waitpid in order to do so, and it does not seem worthwhile to me to do so since it does no harm to open the file in the parent process.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: using a pipe
by drock (Beadle) on Dec 30, 2005 at 19:48 UTC |