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
27 child_watch_cb (GPid pid,
31 GMainLoop* loop = data;
33 g_main_loop_quit (loop);
37 child_out_cb (GIOChannel * source,
38 GIOCondition condition,
46 status = g_io_channel_read_chars (source, buffer, sizeof(buffer), &length, &error);
47 if (status == G_IO_STATUS_NORMAL)
49 g_print ("%d\n", length);
54 g_print ("Output done: %d\n", status);
64 GError * error = NULL;
66 gchar * working_folder;
67 gchar * child_argv[] = {
75 working_folder = g_get_current_dir ();
76 g_spawn_async_with_pipes (working_folder,
77 child_argv, NULL /* envp */,
78 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
85 g_free (working_folder);
89 g_error ("Couldn't execute child: %s", error->message);
93 loop = g_main_loop_new (NULL, FALSE);
95 g_child_watch_add (pid,
99 out = g_io_channel_unix_new (child_out);
100 g_io_add_watch (out, G_IO_IN,
103 g_main_loop_run (loop);
104 g_main_loop_unref (loop);