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


In reply to IPC::Open2 Help. by zzspectrez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.