Re: how to use socketpair to run another program

2002-08-01 Thread Steve Grazzini

Ken <[EMAIL PROTECTED]> wrote:
> I have an external program (not in perl, and not written by me). 
> I want to send a string to it, have it do it's thing, then return 
> the output to my perl program. Then, depending on the results, I 
> might need to run the external program again with a different string.
>
> I'm close with the following:
> open BL, "|-", "bl -d /usr/local/share/bl"  #open program with parameters
>   or die "cant open bl fork: $!";
> local $SIG{PIPE} = sub { die "bl pipe broke"}; 
> print BL "stuff\n\n";   #send this to the program bl
> close BL or die "bad close $!";
> 
> This sends the output to the screen, STDOUT. So I think my next 
> step is to use a socketpair so I can gather the ouput and use it.
> But I can't figure out how to set this up. 

Switching to IPC::Open2 would be easier:

  use IPC::Open2;

  my $pid = open2 *BLR, *BLW, qw(bl -d /usr/local/share/bl)
 or die "cant open bl fork: $!";
  local $SIG{PIPE} = sub { die "bl pipe broke" }; 

  print BLW "stuff\n\n";

  my $reply = ;

  # etc...

  close BLW or die "close bl writer: $!";
  close BLR or die "close bl reader $!";

  waitpid $pid, 0;

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




how to use socketpair to run another program

2002-07-31 Thread Ken

I've looked at Programming Perl and the Perl Cookbook, but I'm just too dense 
to figure out how to do this.
I have an external program (not in perl, and not written by me). I want to 
send a string to it, have it do it's thing, then return the output to my perl 
program. Then, depending on the results, I might need to run the external 
program again with a different string.
I'm close with the following:
open BL, "|-", "bl -d /usr/local/share/bl"  #open program with parameters
or die "cant open bl fork: $!";
local $SIG{PIPE} = sub { die "bl pipe broke"}; 
print BL "stuff\n\n";   #send this to the program bl
close BL or die "bad close $!";

This sends the output to the screen, STDOUT. So I think my next step is to 
use a socketpair so I can gather the ouput and use it.
But I can't figure out how to set this up. 

Using the example in the Perl Cookbook (p. 575), here's the line that stumps 
me.
socketpair (CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC)

this is what I tried, along with other variations (no laughing please)
socketpair (CHILD |- "bl -d /usr/local/share/bl", PARENT, AF_UNIX, 
SOCK_STREAM, PF_UNSPEC)

Any help is appreciated
Ken

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]