Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Output pipes

Reply
Thread Tools

Output pipes

 
 
Kim Helliwell
Guest
Posts: n/a
 
      12-22-2004
Is there a way to pipe output to a command without the command blocking?
By that I mean: I want to start several xgraph (an x-window graphing app)
sessions from a Perl script, and so far, each session blocks until I dismiss
the window.

I tried:

open(GRAPH, "| xgraph &")

But that gives an error from xgraph that the data stream had errors.

I'm afraid I will have to invoke the whole fork/exec and IO redirection
machinery to do this, but I'd like to find a simpler way if anyone knows
one.

I have been reading the FAQ on system calls, and some of the questions come
close to helping, but not quite.

Any help appreciated. Email me (preferably) at http://www.velocityreviews.com/forums/(E-Mail Removed)

Thanks,

Kim Helliwell

 
Reply With Quote
 
 
 
 
Kim Helliwell
Guest
Posts: n/a
 
      12-22-2004
Guess I wasn't clear. Without the &, it works, but blocks after
each process and waits till the process exits before going on to
the next one.

Kim


On 12/22/04 10:59 AM, in article
221220041059068455%(E-Mail Removed), "Jim Gibson"
<(E-Mail Removed)> wrote:

>
> Have you tried it without the '&'? The open should fork a child
> process, exec the xgraph program, which, if it accepts input from
> stdin, block waiting for input. Meanwhile, your program will continue
> to execute. Unfortunately, I don't have the xgraph program on my system
> to test it.
>


 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      12-22-2004
Kim Helliwell <(E-Mail Removed)> wrote:
> Guess I wasn't clear. Without the &, it works, but blocks after
> each process and waits till the process exits before going on to
> the next one.


What does this mean? What is "it"? It blocks "after each process"....
does what? After each process starts up? After each process gets bored?
After each process exits? Under normal circumstance, I would think "after
a process" would mean after the process finishes and exits. But if it
blocks after the process exits and then unblocks when the process
exits....well, I don't see how that is a problem.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Kim Helliwell
Guest
Posts: n/a
 
      12-22-2004
Once again, forgive the imprecision. I guess I should have included
the context from my original post as well.

I'm piping output from a Perl script to xgraph, which is an X-windows
graphing application (that is, it has a GUI). So when xgraph starts,
it doesn't quit until I mouse-click to close it. And, the script blocks
until that happens. Clear so far?

OK, I want to spawn about 16-32 of these xgraph processes all at once,
instead of one at a time. So I would like my script not to block waiting
for exit of the first xgraph process before spawning the next, and so on.

The question is: how can this be accomplished, short of handling the
fork/exec and IO redirection myself? Can this be accomplished at all
using the open(GRAPH, "| $cmd") syntax?

I hope that is a bit more clear.

Kim


On 12/22/04 12:23 PM, in article 20041222152300.545$(E-Mail Removed),
"(E-Mail Removed)" <(E-Mail Removed)> wrote:

> Kim Helliwell <(E-Mail Removed)> wrote:
>> Guess I wasn't clear. Without the &, it works, but blocks after
>> each process and waits till the process exits before going on to
>> the next one.

>
> What does this mean? What is "it"? It blocks "after each process"....
> does what? After each process starts up? After each process gets bored?
> After each process exits? Under normal circumstance, I would think "after
> a process" would mean after the process finishes and exits. But if it
> blocks after the process exits and then unblocks when the process
> exits....well, I don't see how that is a problem.
>
> Xho


 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      12-22-2004


Kim Helliwell wrote upside down (please don't do that, it is considered
rude):

> I'm piping output from a Perl script to xgraph, which is an X-windows
> graphing application (that is, it has a GUI). So when xgraph starts,
> it doesn't quit until I mouse-click to close it. And, the script blocks
> until that happens. Clear so far?
>
> OK, I want to spawn about 16-32 of these xgraph processes all at once,
> instead of one at a time. So I would like my script not to block waiting
> for exit of the first xgraph process before spawning the next, and so on.
>
> The question is: how can this be accomplished, short of handling the
> fork/exec and IO redirection myself? Can this be accomplished at all
> using the open(GRAPH, "| $cmd") syntax?


AFAIK it is impossible to close a file handle opened using the pipe
syntax (either explicitly or implicitly through reuse) without waiting.
(I even thought this was a FAQ but I can't find it). You need to do the
pipe/fork/exec by hand or by using a different filehandle for each
process. This is most easily achived using autovivified
pseudo-anonymous filehandles.

open(my $graph, '|-', $cmd ) or die $!;
push @graphs => $graph;

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      12-23-2004
Kim Helliwell <(E-Mail Removed)> wrote:
> Once again, forgive the imprecision. I guess I should have included
> the context from my original post as well.
>
> I'm piping output from a Perl script to xgraph, which is an X-windows
> graphing application (that is, it has a GUI). So when xgraph starts,
> it doesn't quit until I mouse-click to close it. And, the script blocks
> until that happens. Clear so far?


Sorry, still not clear. At what point in your script is it blocking?
upon the open of the file handle piped to xgraph? Upon any print to that
file handle? Upon printing over a certain number of bytes to that file
handle? Upon closing that file handle?

I don't see any reason it should block (for more than a brief time) at any
stage except the closing part. In which case, not closing the handles
would be one solution!

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input/Output to IRB using Pipes Narayanan K Ruby 2 06-16-2010 11:18 PM
unix pipes to perl scripts trt. Perl 1 03-15-2005 02:25 AM
IPC Mechanism Named pipes or Windows messages or sthg else ? piyush ASP .Net 0 07-14-2004 02:41 PM
IPC::Run and hanging pipes Brian Hann Perl 1 12-11-2003 08:41 PM
Compressing output via pipes Orr, Steve Python 2 11-29-2003 03:36 AM



Advertisments