Re: multiple process calls from GTK



German:

On Fri, 2003-01-10 at 14:47, 447158 celes unizar es wrote:
Hello,

  I am developing an application in GTK+1.2 and my problem is that I want to
execute two processes that communicate between them and then return their
output.

  First, I've got the problem of calling both processes at the same time, as I
don't know how to do it (I know I can use the system() system call to execute
something in a shell, but I don't know if it works for 2 programs...).

  Another problem I have is that it would be great to process the information of
the processes as it is generated (via standard output or another descriptor),
but I don't know how to do it at the same time that these processes are
executed.

  I also would like to be able to stop them whenever a user could think it
necessary, so my GTK application should be active while these processes are
executing...

  You see, concurrency and more concurrency... any help is wellcome!


Check out this post, made on this list on 2002-12-10.

################################################################################

           From: 
Havoc Pennington
<hp redhat com>
             To: 
German Poo
Caaman~o
<gpoo ubiobio cl>
             Cc: 
gtk-app-devel-list gnome org
        Subject: 
Re: The right way
to get the ouput
from a pipe into a
widget
           Date: 
Tue, 10 Dec 2002
18:10:06 -0500

On Tue, Dec 10, 2002 at 07:21:54PM -0300, German Poo Caaman~o wrote:

I'm trying to connect the ouput from programs like ping and
traceroute and show its results into some GTK widgets.  
So, I use pipe, fork and exec.

Use g_spawn_async_with_pipes() instead, it'll immediately make this a
lot simpler.
 
I'd appreaciatte any hint or idea about what I missing,
or if my thought are right or wrong.

What you want to do is:

 - create the child process with g_spawn_async_with_pipes()
   creating a pipe on the child's stdout/stderr
 - use g_io_add_watch() to add a callback to be invoked 
   when there is input on the pipe (G_IO_IN)
 - when there's input, do a single call to read()
   and write the data that you read to the text view. 
   Don't read() twice, or you may block. (Unless you set the 
   pipe nonblocking)
 - when you get G_IO_HUP or G_IO_ERR passed to your IO watch 
   callback, the child process will have exited, so you want 
   to close your end of the pipe, and remove the IO watch.

Havoc

################################################################################

That sounds about like what you are looking for.  I also need to do this
for something I am working on; I just have not gotten to it yet, but
from what Havoc described, it does not seem that it would be too
difficult.

Neil





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]