use IPC::Open3 (); # don't import open3 sub my_open3 { # cmd write read error my %opt = ( write => [], read => [], error => [], cmd => "ls", @_); my $stdin = tied *STDIN; my $stdout = tied *STDOUT; my $stderr = tied *STDERR; # temporarily turn off warnings # "untie attempted while 1 inner references still exist" { local $^W = 0; untie *STDIN if $stdin; untie *STDOUT if $stdout; untie *STDERR if $stderr; } my $pid = IPC::Open3::open3(*WTRFH, *RDRFH, *ERR, $opt{cmd}); unless ($pid) { print "can't fork: $!" if $DEBUG; return 0; } # local $SIG{PIPE} = sub { 1 }; # $pipe_error = 1 }; print WTRFH @{$opt{write}}; # || return 0; # die "can't write: $!"; close (WTRFH); # || return 0; #die "bad pipe: $! $?"; @{$opt{read}} = ; @{$opt{error}} = ; close (RDRFH); # || return 0; #die "bad pipe: $! $?"; close (WTRFH); # || return 0; #die "bad pipe: $! $?"; waitpid $pid, 0; tie *STDIN, ref $stdin, $stdin if $stdin; tie *STDOUT, ref $stdout, $stdout if $stdout; tie *STDERR, ref $stderr, $stderr if $stderr; return 1; # ok } #### my $gpg = "gpg ...options..."; my ($id, $pass, @data) = ('fglock','xxx',"data\n","data\n"); my (@result, @err); unshift @data, $pass . "\n"; $cmd = "$gpg --no-tty --local-user $id --passphrase-fd 0 --decrypt"; my_open3( cmd => $cmd, write => \@data, read => \@result, error => \@err );