zzspectrez has asked for the wisdom of the Perl Monks concerning the following question:
Taking the advice of the fellow monks on one of my previous posts, Im trying to use IPC::Open2or IPC::Open3 to control a forked process. Ok. Im having a tuff time with figuring this out. I have searched for code but havent found many good examples of how to use it. I originally was trying this on a Win32 machine and thought my problems were rooted in windows issues. So now Im trying on my linux box. Still no luck.
For my test, Im trying to spawn pgp and have it encrypt data that I send to it and read back the encrypted output.
First I make sure I have pgp working correctly. I do the following from the shell:
$ export PGPPASS="MY PASSPHRASE" $ echo $PGPPASS MY PASSPHRASE $ pgp -feast zzSPECTREz <test.dat Pretty Good Privacy(tm) 2.6.3a - Public-key encryption for the masses. (c) 1990-96 Philip Zimmermann, Phil's Pretty Good Software. 1996-03-04 Uses the RSAREF(tm) Toolkit, which is copyright RSA Data Security, Inc +. Distributed by the Massachusetts Institute of Technology. Export of this software may be restricted by the U.S. government. Current time: 2000/11/28 08:02 GMT You specified no user ID to select your secret key, so the default user ID and key will be the most recently added key on your secret keyring. Pass phrase is good. Just a moment.... Key for user ID: zzSPECTREz <zzspectrez@yahoo.com> 1024-bit key, key ID 30331F8D, created 2000/11/28 .-----BEGIN PGP MESSAGE----- Version: 2.6.3a hIwDFugMGjAzH40BA/0QTFT3pazbHqhMp7tGiXDG0GBhvc1LOO3Nq0JUxyHKzNRo Zy8KMS186W+bVtEx0Bcp7EWVlQdt9JtFTYl0D9+zitKCmFpg0RT0mWNH9hEtixr3 WufvK4p0B/0wQKQypgS8rl/+cNR4+uGUbsD8YremUDBV8+YoE5B5yn5jh/mYvaYA AADnyBa016F+SSgwl5tUSgDZVBeMnl5mWmGvLivqG5NYrvyb4AATFgPQPeOzksGM bJKf5E3q9uxvtl7mZOuNCf6VC8lZPAt1NGHrGBMwCkptR835ZV1kSoSEMZhU1+nC 6i4g1VZA3bYyE5fOK4gA3IfhRAyvhYY5guCe9ff1+FtGSIVXmR3D8y4GaOrALhAZ FiK3B/FXx81coA3S7xOJnyVbBvTSh0ncppZwE5TvmK5anD4Hl8eJSZsJjwK5Jd5z 9Hs1nbqhAUs96PDnqjRMIP+sPU8dCRgylq9SwombStl18IEtvo/R4XHV =yeUi -----END PGP MESSAGE-----
Now for my test code.
#!/usr/bin/perl -w use strict; use IPC::Open2 use FileHandle; $ENV{PGPPASS} = "MY PASSPHRASE"; print "\nEnter user id: "; my $user_id = <STDIN>; chomp $user_id; print "\nInput file: "; my $inp_file = <STDIN>; chomp $inp_file; open (INFILE, $inp_file) or die ("Could not open $inp_file: $!\n"); my @in_data = <INFILE>; close (INFILE); my $pid = open2(\*READER, \*WRITER, 'pgp -feast $user_id') or warn "$!\n"; READER->autoflush(); WRITER->autoflush(); print WRITER @in_data; while (<READER>) { print; }
This code runs and then hangs with the following output:
$ ./pgpify.pl Enter user id: zzSPECTREz Input file: test.dat Pretty Good Privacy(tm) 2.6.3a - Public-key encryption for the masses. (c) 1990-96 Philip Zimmermann, Phil's Pretty Good Software. 1996-03-04 Uses the RSAREF(tm) Toolkit, which is copyright RSA Data Security, Inc +. Distributed by the Massachusetts Institute of Technology. Export of this software may be restricted by the U.S. government. Current time: 2000/11/28 07:51 GMT
I thought it might be that I had to read the output of the program before writing the data to it so I tried adding the followin: my @junk = <READER>. Didnt help. Any suggestions?
Thanks!
zzSPECTREz
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IPC::Open2 Help.
by geektron (Curate) on Nov 28, 2000 at 13:35 UTC | |
|
Re: IPC::Open2 Help.
by repson (Chaplain) on Nov 28, 2000 at 17:09 UTC | |
by zzspectrez (Hermit) on Nov 28, 2000 at 22:24 UTC | |
|
Re: IPC::Open2 Help.
by jepri (Parson) on Nov 28, 2000 at 15:00 UTC | |
by zzspectrez (Hermit) on Nov 28, 2000 at 22:48 UTC | |
|
Re: IPC::Open2 Help.
by zzspectrez (Hermit) on Nov 30, 2000 at 00:43 UTC |