1 /* This file is part of gtester
4 * Sven Herzberg <herzi@gnome-de.org>
6 * Copyright (C) 2007 Sven Herzberg
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2.1 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 /* the read buffer size in bytes */
27 #define READ_BUFFER_SIZE 1024
29 static GIOChannel* out = NULL;
32 child_out_cb (GIOChannel * source,
33 GIOCondition condition,
38 gchar buffer[READ_BUFFER_SIZE];
39 GIOStatus status = G_IO_STATUS_NORMAL;
41 while (status == G_IO_STATUS_NORMAL) {
42 status = g_io_channel_read_chars (source, buffer, sizeof (buffer), &length, &error);
45 case G_IO_STATUS_NORMAL:
46 // FIXME: this is where the parsing happens
47 g_print ("%d\n", length);
49 case G_IO_STATUS_AGAIN:
52 case G_IO_STATUS_ERROR:
53 /* fall through into EOF */
54 g_warning ("Error while reading data: %s",
66 child_watch_cb (GPid pid,
70 GMainLoop* loop = data;
72 g_spawn_close_pid (pid);
74 /* read the remaining data - also stops the io watch from being polled */
75 child_out_cb (out, G_IO_IN, data);
76 g_main_loop_quit (loop);
84 GError * error = NULL;
86 gchar * working_folder;
87 gchar * child_argv[] = {
95 working_folder = g_strdup ("/home/herzi/Hacking/Imendio/WebKit/WebCore"); //g_get_current_dir ();
96 g_spawn_async_with_pipes (working_folder,
97 child_argv, NULL /* envp */,
98 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
105 g_free (working_folder);
109 g_error ("Couldn't execute child: %s", error->message);
113 loop = g_main_loop_new (NULL, FALSE);
115 g_child_watch_add (pid,
119 out = g_io_channel_unix_new (child_out);
120 g_io_channel_set_flags (out, G_IO_FLAG_NONBLOCK, NULL); // FIXME: GError
121 g_io_add_watch (out, G_IO_IN,
124 g_main_loop_run (loop);
125 g_main_loop_unref (loop);