[ic] IPC::Open2 inside GlobalSub

Mark Johnson markj@redhat.com
Fri, 09 Mar 2001 17:25:35 -0500

Mike Heins wrote:
> 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.

Even that doesn't seem to work. I ran into this for a payment gateway
using open2, and you are right that it chokes without being attached to
a terminal. Even closing and opening STDIN/OUT, and localizing, doesn't

However, you *can* work around this in a kludgy way (thanks to Sonny
Cook for the idea!). Pick some way to generate a unique filename
(session ID would work nicely for an IC purpose), and

use FileHandle;

my $rec_data;
my $tmp_file = "$Config->{ScratchDir}/$Session->{id}";

open (Writer,"| $encrypt_command > $tmp_file") or die "Can't open pipe
to encrypt prog: $!\n";

print Writer $data;

open (Reader,"<$tmp_file") or die "Can't open $tmp_file: $!\n";
  $rec_data = <Reader>;

unlink ($tmp_file);

return $rec_data; 

Of course, replace your error handling any way you see fit, perhaps in
an eval {} block as you have it currently.

> --
> 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
> _______________________________________________
> Interchange-users mailing list
> Interchange-users@lists.akopia.com
> http://lists.akopia.com/mailman/listinfo/interchange-users

Mark Johnson
Senior Developer - Professional Services
Red Hat, Inc.
E-Business Solutions