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)
64 sprintf (buf
, "spawn-test-win32-gui: Write: %s", strerror (errsv
));
65 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
69 MessageBox (NULL
, "spawn-test-win32-gui: Will read from parent",
70 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
72 if ((k
= read (infd
, &n
, sizeof (n
))) != sizeof (n
))
74 sprintf (buf
, "spawn-test-win32-gui: Got only %d bytes, wanted %d",
76 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
80 sprintf (buf
, "spawn-test-win32-gui: Parent says %d bytes to read", n
);
81 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
83 if ((k
= read (infd
, buf
, n
)) != n
)
87 sprintf (buf
, "spawn-test-win32-gui: Read: %s", strerror (errsv
));
89 sprintf (buf
, "spawn-test-win32-gui: Got only %d bytes", k
);
90 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
94 MessageBox (NULL
, "spawn-test-win32-gui: Will write more to parent",
95 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);
97 n
= strlen ("See ya");
98 if (write (outfd
, &n
, sizeof (n
)) == -1 ||
99 write (outfd
, "See ya", n
) == -1)
102 sprintf (buf
, "spawn-test-win32-gui: Write: %s", strerror (errsv
));
103 MessageBox (NULL
, buf
, lpszCmdLine
, MB_ICONERROR
|MB_SYSTEMMODAL
);
110 MessageBox (NULL
, "spawn-test-win32-gui: Done, exiting.",
111 lpszCmdLine
, MB_ICONINFORMATION
|MB_SYSTEMMODAL
);