Home > Archive > PERL Beginners > August 2005 > two way piped open
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
two way piped open
|
|
| Bryan R Harris 2005-08-24, 6:56 pm |
|
I'd like to open 2-way pipe to a tool that we have here. It's called
yprtool and once it's open, you give it 3 numbers to its STDIN and it spits
out 3 numbers to its STDOUT. It stays open until you ctrl-c it.
What's the correct syntax for opening something like this?
This doesn't work:
**************************************
$yprtool = '/Users/bh/Library/models/yprtool';
open(YPRTOOL, "+<$yprtool|") or die "open error blah";
print YPRTOOL "$a $b $c\n";
$return = <YPRTOOL>;
close(YPRTOOL) or die "a cruel death";
**************************************
I think the problem is in the "+<", but I'm not sure.
- B
| |
| Wiggins d'Anconia 2005-08-24, 6:56 pm |
| Bryan R Harris wrote:
>
> I'd like to open 2-way pipe to a tool that we have here. It's called
> yprtool and once it's open, you give it 3 numbers to its STDIN and it spits
> out 3 numbers to its STDOUT. It stays open until you ctrl-c it.
>
> What's the correct syntax for opening something like this?
>
> This doesn't work:
>
> **************************************
> $yprtool = '/Users/bh/Library/models/yprtool';
> open(YPRTOOL, "+<$yprtool|") or die "open error blah";
> print YPRTOOL "$a $b $c\n";
> $return = <YPRTOOL>;
> close(YPRTOOL) or die "a cruel death";
> **************************************
>
> I think the problem is in the "+<", but I'm not sure.
>
> - B
>
Check out the IPC::Open2 and IPC::Open3 modules, they are standard.
perldoc IPC::Open2
perldoc IPC::Open3
Additionally there is good information available in,
perldoc perlipc
http://danconia.org
| |
| Bryan R Harris 2005-08-24, 6:56 pm |
|
That does it, thanks, Wiggins!
- B
> Bryan R Harris wrote:
>
> Check out the IPC::Open2 and IPC::Open3 modules, they are standard.
>
> perldoc IPC::Open2
> perldoc IPC::Open3
>
> Additionally there is good information available in,
>
> perldoc perlipc
>
> http://danconia.org
| |
| Bryan R Harris 2005-08-24, 6:56 pm |
|
And a follow-on question:
Any idea why I have to send the yprtool two "\n"s instead of one to make it
work? With just one it hangs... On the command line, it definitely works
with just one.
**************************************
($y,$p,$r) = (split(' ', $lines[15]))[11..13];
use IPC::Open2;
local (*GETYPR, *SENDYPR);
$pid = open2(\*GETYPR, \*SENDYPR, "$yprtool -l 90 0 0 ");
print SENDYPR "$y $p $r\n\n";
($y2, $p2, $r2) = split(' ',<GETYPR> );
close GETYPR;
close SENDYPR;
print "y: $y, p: $p, r: $r\n";
print "y2: $y2, p2: $p2, r2: $r2\n";
**************************************
TIA.
- Bryan
> That does it, thanks, Wiggins!
>
> - B
>
>
>
>
>
| |
| Timothy Johnson 2005-08-24, 6:56 pm |
|
Just a thought, but this behavior might be caused by Perl buffering your
output. =20
Try selecting your file handle and then setting $| to 1. That way Perl
should send your output immediately.
-----Original Message-----
From: Bryan R Harris [mailto:Bryan_R_Harris@raytheon.com]=20
Sent: Wednesday, August 24, 2005 1:51 PM
To: Beginners Perl
Subject: Re: two way piped open
And a follow-on question:
Any idea why I have to send the yprtool two "\n"s instead of one to make
it
work? With just one it hangs... On the command line, it definitely
works
with just one.
<snip>
| |
| Bryan R Harris 2005-08-24, 6:56 pm |
|
Makes sense, but that's not it, unfortunately. I tried it and it still
hangs...
Also, strangely, with the two "\n"s, the next time I try to write to the
filehandle it says the pipe is broken.
Here's sample output from the tool:
**************************************
ralph 2104% yprtool -l 90 0 0
50 50 50 <- I type this
130.000000 -50.000000 -130.000000 <- it outputs this
40 40 40 <- I type this
140.000000 -40.000000 -140.000000 <- it outputs this
<- I type a return
ERROR: Wrong number of inputs in stream. <- and it complains
Throwing exception (1: "1") at ../src/YprTool.cpp line 192.
Program error...exiting
**************************************
- B
>
> Just a thought, but this behavior might be caused by Perl buffering your
> output.
>
> Try selecting your file handle and then setting $| to 1. That way Perl
> should send your output immediately.
>
>
>
>
> -----Original Message-----
> From: Bryan R Harris [mailto:Bryan_R_Harris@raytheon.com]
> Sent: Wednesday, August 24, 2005 1:51 PM
> To: Beginners Perl
> Subject: Re: two way piped open
>
>
>
> And a follow-on question:
>
> Any idea why I have to send the yprtool two "\n"s instead of one to make
> it
> work? With just one it hangs... On the command line, it definitely
> works
> with just one.
>
> <snip>
>
>
| |
| Bryan R Harris 2005-08-24, 6:56 pm |
|
Figured it out, Timothy had the right idea. The tool was buffering its
output!
- B
> Makes sense, but that's not it, unfortunately. I tried it and it still
> hangs...
>
> Also, strangely, with the two "\n"s, the next time I try to write to the
> filehandle it says the pipe is broken.
>
> Here's sample output from the tool:
>
> **************************************
> ralph 2104% yprtool -l 90 0 0
> 50 50 50 <- I type this
> 130.000000 -50.000000 -130.000000 <- it outputs this
> 40 40 40 <- I type this
> 140.000000 -40.000000 -140.000000 <- it outputs this
> <- I type a return
>
> ERROR: Wrong number of inputs in stream. <- and it complains
>
> Throwing exception (1: "1") at ../src/YprTool.cpp line 192.
> Program error...exiting
> **************************************
>
> - B
>
>
>
>
>
>
>
|
|
|
|
|