Re: Call external programs and keep showing its outputs



After step 3, you may need to do:

    g_io_channel_set_encoding (iochan, NULL, NULL);
    g_io_channel_set_buffer_size(iochan, 0);
    g_io_channel_set_flags(iochan, G_IO_FLAG_NONBLOCK, &gerr);


Salsaman.




http://lives.sourceforge.net
https://www.ohloh.net/accounts/salsaman


On Thu, Oct 10, 2013 at 8:35 AM, Kang Hu <hukangustc gmail com> wrote:

see https://developer.gnome.org/glib/2.38/glib-Spawning-Processes.html#g-spawn-async-with-pipes

1. call g_spawn_async_with_pipes and get the stdin, stdout, stderr fds.
2. call g_child_watch on the pid returned in step 1.
3. create an io channel for each fd ( see g_io_channel_unix_new)
4. add each io channel to the main loop ( see g_io_add_watch) .
   read external  application output (see g_io_channel_read_*)  in the callback function GIOFunc 
   and update your widget's text section
5. you can kill external programs by the pid you get in step 1.
NOTE: you need to release fds in callbacks in step 2.


On Thu, Oct 10, 2013 at 12:55 PM, Woody Wu <narkewoody gmail com> wrote:
Hi,

I am about to write a test runner with GTK+. It basically can list a lot
of external test programs (non-GTK+ pure Linux apps) in a treeview and
let user select one of them to run. While an external program is
running, I want to get all its outputs (to stdout/stderr) and keep
updating in a textview.

Since I am a Linux programmer, so I know how to fork a new process and
pipe into an external program. But I don't know in GTK+, what's the
right method to keep fetching the information from the pipe and showing
them in my GUI widgets.  On the other hand, while an external program is
running, I don't want user feel that the my program is frozing and user
should be able to kill the running external program by clicking a 'stop'
button on the GUI.

For this kind of task, what GTK+ technology I should go to grab?  Thanks
in advance!

--
I can't go back to yesterday - because I was a different person then
_______________________________________________
gtk-list mailing list
gtk-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-list


_______________________________________________
gtk-list mailing list
gtk-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-list




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