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
47 gchar *erroutput = NULL;
48 int pipedown[2], pipeup[2];
52 printf ("The following errors are supposed to occur:\n");
55 if (!g_spawn_command_line_sync ("nonexistent_application foo 'bar baz' blah blah",
59 fprintf (stderr, "Error (normal, supposed to happen): %s\n", err->message);
64 if (!g_spawn_command_line_async ("nonexistent_application foo bar baz \"blah blah\"",
67 fprintf (stderr, "Error (normal, supposed to happen): %s\n", err->message);
71 printf ("Errors after this are not supposed to happen:\n");
75 if (!g_spawn_command_line_sync ("/bin/sh -c 'echo hello'",
79 fprintf (stderr, "Error: %s\n", err->message);
85 g_assert (output != NULL);
87 if (strcmp (output, "hello\n") != 0)
89 printf ("output was '%s', should have been 'hello'\n",
99 printf ("Running ipconfig synchronously, collecting its output\n");
101 if (!g_spawn_command_line_sync ("ipconfig /all",
102 &output, &erroutput, NULL,
105 fprintf (stderr, "Error: %s\n", err->message);
111 g_assert (output != NULL);
112 g_assert (erroutput != NULL);
114 if (strstr (output, "IP Configuration") == 0)
116 printf ("output was '%s', should have contained 'IP Configuration'\n",
121 if (erroutput[0] != '\0')
123 printf ("error output was '%s', should have been empty\n",
134 printf ("Starting spawn-test-win32-gui asynchronously (without wait).\n"
135 "Click on the OK buttons.\n");
137 if (!g_spawn_command_line_async ("'.\\spawn-test-win32-gui.exe' 1", &err))
139 fprintf (stderr, "Error: %s\n", err->message);
144 printf ("Running spawn-test-win32-gui synchronously,\n"
145 "collecting its output. Click on the OK buttons.\n");
146 if (!g_spawn_command_line_sync ("'.\\spawn-test-win32-gui.exe' 2",
147 &output, &erroutput, NULL,
150 fprintf (stderr, "Error: %s\n", err->message);
156 g_assert (output != NULL);
157 g_assert (erroutput != NULL);
159 if (strcmp (output, "This is stdout\r\n") != 0)
161 printf ("output was '%s', should have been 'This is stdout'\n",
162 g_strescape (output, NULL));
166 if (strcmp (erroutput, "This is stderr\r\n") != 0)
168 printf ("error output was '%s', should have been 'This is stderr'\n",
169 g_strescape (erroutput, NULL));
177 printf ("Running spawn-test-win32-gui asynchronously again.\n"
178 "This time talking to it through pipes. Click on the OK buttons.\n");
180 if (pipe (pipedown) < 0 ||
183 fprintf (stderr, "Could not create pipes\n");
187 if (!g_shell_parse_argv (g_strdup_printf ("'.\\spawn-test-win32-gui.exe' pipes %d %d",
188 pipedown[0], pipeup[1]),
192 fprintf (stderr, "Error parsing command line? %s\n", err->message);
197 if (!g_spawn_async (NULL, argv, NULL,
198 G_SPAWN_LEAVE_DESCRIPTORS_OPEN |
199 G_SPAWN_DO_NOT_REAP_CHILD,
203 fprintf (stderr, "Error: %s\n", err->message);
212 if ((k = read (pipeup[0], &n, sizeof (n))) != sizeof (n))
215 fprintf (stderr, "Read error: %s\n", g_strerror (errno));
217 fprintf (stderr, "Wanted to read %d bytes, got %d\n",
222 if ((k = read (pipeup[0], buf, n)) != n)
225 fprintf (stderr, "Read error: %s\n", g_strerror (errno));
227 fprintf (stderr, "Wanted to read %d bytes, got %d\n",
232 n = strlen ("Bye then");
233 if (write (pipedown[1], &n, sizeof (n)) == -1 ||
234 write (pipedown[1], "Bye then", n) == -1)
236 fprintf (stderr, "Write error: %s\n", g_strerror (errno));
240 if ((k = read (pipeup[0], &n, sizeof (n))) != sizeof (n))
243 fprintf (stderr, "Read error: %s\n", g_strerror (errno));
245 fprintf (stderr, "Wanted to read %d bytes, got %d\n",
250 if ((k = read (pipeup[0], buf, n)) != n)
253 fprintf (stderr, "Read error: %s\n", g_strerror (errno));
255 fprintf (stderr, "Wanted to read %d bytes, got %d\n",