9 /* For read() and write() */
11 /* Cygwin does not prototype __argc and __argv in stdlib.h */
17 WinMain (struct HINSTANCE__
*hInstance
,
18 struct HINSTANCE__
*hPrevInstance
,
24 if (__argc
>= 2 && strcmp (__argv
[1], "nop") == 0)
26 sprintf (buf
, "spawn-test-win32-gui: argv[0]=\"%s\"", __argv
[0]);
27 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
31 MessageBox (NULL
, "spawn-test-win32-gui: Will write to stdout",
32 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
34 printf ("This is stdout\n");
37 MessageBox (NULL
, "spawn-test-win32-gui: Will write to stderr",
38 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
40 fprintf (stderr
, "This is stderr\n");
43 else if (__argc
== 4 && strcmp (__argv
[1], "pipes") == 0)
45 int infd
= atoi (__argv
[2]);
46 int outfd
= atoi (__argv
[3]);
49 if (infd
< 0 || outfd
< 0)
51 MessageBox (NULL
, "spawn-test-win32-gui: illegal fds on command line",
52 lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
56 MessageBox (NULL
, "spawn-test-win32-gui: Will write to parent",
57 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
59 n
= strlen ("Hello there");
60 if (write (outfd
, &n
, sizeof (n
)) == -1 ||
61 write (outfd
, "Hello there", n
) == -1)
63 sprintf (buf
, "spawn-test-win32-gui: Write: %s", strerror (errno
));
64 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
68 MessageBox (NULL
, "spawn-test-win32-gui: Will read from parent",
69 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
71 if ((k
= read (infd
, &n
, sizeof (n
))) != sizeof (n
))
73 sprintf (buf
, "spawn-test-win32-gui: Got only %d bytes, wanted %d",
75 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
79 sprintf (buf
, "spawn-test-win32-gui: Parent says %d bytes to read", n
);
80 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
82 if ((k
= read (infd
, buf
, n
)) != n
)
85 sprintf (buf
, "spawn-test-win32-gui: Read: %s", strerror (errno
));
87 sprintf (buf
, "spawn-test-win32-gui: Got only %d bytes", k
);
88 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
92 MessageBox (NULL
, "spawn-test-win32-gui: Will write more to parent",
93 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
95 n
= strlen ("See ya");
96 if (write (outfd
, &n
, sizeof (n
)) == -1 ||
97 write (outfd
, "See ya", n
) == -1)
99 sprintf (buf
, "spawn-test-win32-gui: Write: %s", strerror (errno
));
100 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
107 MessageBox (NULL
, "spawn-test-win32-gui: Done, exiting.",
108 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);