From: Tim Janik Date: Tue, 20 Nov 2007 15:00:36 +0000 (+0000) Subject: glib/gtester.c:Read the output of the child process X-Git-Tag: GLIB_2_15_1~350 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dce1a63bf4ef7e8f73fea66436d2c4377015979f;p=platform%2Fupstream%2Fglib.git glib/gtester.c:Read the output of the child process svn path=/trunk/; revision=5890 --- diff --git a/glib/gtester.c b/glib/gtester.c index b695752..f738a12 100644 --- a/glib/gtester.c +++ b/glib/gtester.c @@ -28,9 +28,32 @@ child_watch_cb (GPid pid, gint status, gpointer data) { - GMainLoop* loop = data; + GMainLoop* loop = data; - g_main_loop_quit (loop); + g_main_loop_quit (loop); +} + +static gboolean +child_out_cb (GIOChannel * source, + GIOCondition condition, + gpointer data) +{ + GError* error = NULL; + gsize length = 0; + gchar buffer[4096]; + GIOStatus status; + + status = g_io_channel_read_chars (source, buffer, sizeof(buffer), &length, &error); + if (status == G_IO_STATUS_NORMAL) + { + g_print ("%d\n", length); + return TRUE; + } + else + { + g_print ("Output done: %d\n", status); + return FALSE; + } } int @@ -46,6 +69,8 @@ main (int argc, "/proc/cpuinfo", NULL }; + gint child_out; + GIOChannel* out; working_folder = g_get_current_dir (); g_spawn_async_with_pipes (working_folder, @@ -54,7 +79,7 @@ main (int argc, NULL, NULL, &pid, NULL, - NULL, + &child_out, NULL, &error); g_free (working_folder); @@ -71,6 +96,10 @@ main (int argc, child_watch_cb, loop); + out = g_io_channel_unix_new (child_out); + g_io_add_watch (out, G_IO_IN, + child_out_cb, NULL); + g_main_loop_run (loop); g_main_loop_unref (loop); return 0;