1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #undef G_DISABLE_ASSERT
46 gchar *erroutput = NULL;
47 int pipedown[2], pipeup[2];
51 printf ("The following errors are supposed to occur:\n");
54 if (!g_spawn_command_line_sync ("nonexistent_application foo 'bar baz' blah blah",
58 fprintf (stderr, "Error (normal, supposed to happen): %s\n", err->message);
63 if (!g_spawn_command_line_async ("nonexistent_application foo bar baz \"blah blah\"",
66 fprintf (stderr, "Error (normal, supposed to happen): %s\n", err->message);
70 printf ("Errors after this are not supposed to happen:\n");
74 if (!g_spawn_command_line_sync ("/bin/sh -c 'echo hello'",
78 fprintf (stderr, "Error: %s\n", err->message);
84 g_assert (output != NULL);
86 if (strcmp (output, "hello\n") != 0)
88 printf ("output was '%s', should have been 'hello'\n",
98 printf ("Running ipconfig synchronously, collecting its output\n");
100 if (!g_spawn_command_line_sync ("ipconfig /all",
101 &output, &erroutput, NULL,
104 fprintf (stderr, "Error: %s\n", err->message);
110 g_assert (output != NULL);
111 g_assert (erroutput != NULL);
113 if (strstr (output, "IP Configuration") == 0)
115 printf ("output was '%s', should have contained 'IP Configuration'\n",
120 if (erroutput[0] != '\0')
122 printf ("error output was '%s', should have been empty\n",
133 printf ("Starting spawn-test-win32-gui asynchronously (without wait).\n"
134 "Click on the OK buttons.\n");
136 if (!g_spawn_command_line_async ("'.\\spawn-test-win32-gui.exe' 1", &err))
138 fprintf (stderr, "Error: %s\n", err->message);
143 printf ("Running spawn-test-win32-gui synchronously,\n"
144 "collecting its output. Click on the OK buttons.\n");
145 if (!g_spawn_command_line_sync ("'.\\spawn-test-win32-gui.exe' 2",
146 &output, &erroutput, NULL,
149 fprintf (stderr, "Error: %s\n", err->message);
155 g_assert (output != NULL);
156 g_assert (erroutput != NULL);
158 if (strcmp (output, "This is stdout\r\n") != 0)
160 printf ("output was '%s', should have been 'This is stdout'\n",
161 g_strescape (output, NULL));
165 if (strcmp (erroutput, "This is stderr\r\n") != 0)
167 printf ("error output was '%s', should have been 'This is stderr'\n",
168 g_strescape (erroutput, NULL));
176 printf ("Running spawn-test-win32-gui asynchronously again.\n"
177 "This time talking to it through pipes. Click on the OK buttons.\n");
179 if (pipe (pipedown) < 0 ||
182 fprintf (stderr, "Could not create pipes\n");
186 if (!g_shell_parse_argv (g_strdup_printf ("'.\\spawn-test-win32-gui.exe' pipes %d %d",
187 pipedown[0], pipeup[1]),
191 fprintf (stderr, "Error parsing command line? %s\n", err->message);
196 if (!g_spawn_async (NULL, argv, NULL,
197 G_SPAWN_LEAVE_DESCRIPTORS_OPEN |
198 G_SPAWN_DO_NOT_REAP_CHILD,
202 fprintf (stderr, "Error: %s\n", err->message);
211 if ((k = read (pipeup[0], &n, sizeof (n))) != sizeof (n))
214 fprintf (stderr, "Read error: %s\n", g_strerror (errno));
216 fprintf (stderr, "Wanted to read %d bytes, got %d\n",
221 if ((k = read (pipeup[0], buf, n)) != n)
224 fprintf (stderr, "Read error: %s\n", g_strerror (errno));
226 fprintf (stderr, "Wanted to read %d bytes, got %d\n",
231 n = strlen ("Bye then");
232 if (write (pipedown[1], &n, sizeof (n)) == -1 ||
233 write (pipedown[1], "Bye then", n) == -1)
235 fprintf (stderr, "Write error: %s\n", g_strerror (errno));
239 if ((k = read (pipeup[0], &n, sizeof (n))) != sizeof (n))
242 fprintf (stderr, "Read error: %s\n", g_strerror (errno));
244 fprintf (stderr, "Wanted to read %d bytes, got %d\n",
249 if ((k = read (pipeup[0], buf, n)) != n)
252 fprintf (stderr, "Read error: %s\n", g_strerror (errno));
254 fprintf (stderr, "Wanted to read %d bytes, got %d\n",