8 WinMain (struct HINSTANCE__ *hInstance,
9 struct HINSTANCE__ *hPrevInstance,
15 MessageBox (NULL, "spawn-test-win32-gui: Will write to stdout",
16 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
18 printf ("This is stdout\n");
21 MessageBox (NULL, "spawn-test-win32-gui: Will write to stderr",
22 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
24 fprintf (stderr, "This is stderr\n");
27 else if (__argc == 4 && strcmp (__argv[1], "pipes") == 0)
29 int infd = atoi (__argv[2]);
30 int outfd = atoi (__argv[3]);
34 if (infd < 0 || outfd < 0)
36 MessageBox (NULL, "spawn-test-win32-gui: illegal fds on command line",
37 lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
41 MessageBox (NULL, "spawn-test-win32-gui: Will write to parent",
42 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
44 n = strlen ("Hello there");
45 if (write (outfd, &n, sizeof (n)) == -1 ||
46 write (outfd, "Hello there", n) == -1)
48 sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errno));
49 MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
53 MessageBox (NULL, "spawn-test-win32-gui: Will read from parent",
54 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
56 if ((k = read (infd, &n, sizeof (n))) != sizeof (n))
58 sprintf (buf, "spawn-test-win32-gui: Got only %d bytes, wanted %d",
60 MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
64 sprintf (buf, "spawn-test-win32-gui: Parent says %d bytes to read", n);
65 MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
67 if ((k = read (infd, buf, n)) != n)
70 sprintf (buf, "spawn-test-win32-gui: Read: %s", strerror (errno));
72 sprintf (buf, "spawn-test-win32-gui: Got only %d bytes", k);
73 MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
77 MessageBox (NULL, "spawn-test-win32-gui: Will write more to parent",
78 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
80 n = strlen ("See ya");
81 if (write (outfd, &n, sizeof (n)) == -1 ||
82 write (outfd, "See ya", n) == -1)
84 sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errno));
85 MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
90 MessageBox (NULL, "spawn-test-win32-gui: Sleeping a bit.",
91 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
95 MessageBox (NULL, "spawn-test-win32-gui: Done, exiting.",
96 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);