![]() |
|
Perl Monk, Perl Meditation | |
PerlMonks |
Re^3: using a pipeby Celada (Monk) |
on Dec 30, 2005 at 06:00 UTC ( #519952=note: print w/replies, xml ) | Need Help?? |
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 as
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:
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.
In Section
Seekers of Perl Wisdom
|
|