[ic] IPC::Open2 inside GlobalSub

Mike Heins mikeh@minivend.com
Wed, 7 Mar 2001 20:51:02 -0500


Quoting Sam Hui (shui@lunamedium.com):
> Hi,
> 
> I'm trying to encrypt some data using a globalsub and an external binary,
> but somehow the $data isn't getting out to the $encrypt_cmd via "Writer"
> handle.  This code runs perfectly fine on a perl script by itself...  I'm
> not getting any errors and using the ::logDebug statements, the code is
> being excuted and the $encrypt_cmd is being called.  I know this because
> open2 returns a different process id everytime the code runs.  Could someone
> shine some light on this?  Much appreciated.
> 
> GlobalSub <<EOS
> sub encrypt_some_data {
> 
>     use FileHandle;
>     use IPC::Open2;
> 
>     my $rec_data;
>     my $pid = eval{
>         open2(\*Reader, \*Writer, "$encrypt_cmd");
>         Writer->autoflush;
>         print Writer "$data";
>         close(Writer);
> 
>         local($/) = undef;
>         $rec_data = <Reader>;
>         close(Reader);
>     };
>     return($rec_data);
> }
> 

STDOUT and STDIN are not what you think in Interchange -- it is a daemon.
It may or may not be possible to do this -- you probably would have to
close and reopen them.

-- 
Red Hat, Inc., 131 Willow Lane, Floor 2, Oxford, OH  45056
phone +1.513.523.7621 fax 7501 <mheins@redhat.com>

Light travels faster than sound. This is why some people appear bright
until you hear them speak. -- unknown