|
Packit |
ae235b |
#include <windows.h>
|
|
Packit |
ae235b |
#include <errno.h>
|
|
Packit |
ae235b |
#include <stdio.h>
|
|
Packit |
ae235b |
#include <string.h>
|
|
Packit |
ae235b |
#include <stdlib.h>
|
|
Packit |
ae235b |
#include <fcntl.h>
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#ifdef __CYGWIN__
|
|
Packit |
ae235b |
/* For read() and write() */
|
|
Packit |
ae235b |
#include <unistd.h>
|
|
Packit |
ae235b |
/* Cygwin does not prototype __argc and __argv in stdlib.h */
|
|
Packit |
ae235b |
extern int __argc;
|
|
Packit |
ae235b |
extern char** __argv;
|
|
Packit |
ae235b |
#endif
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
int _stdcall
|
|
Packit |
ae235b |
WinMain (struct HINSTANCE__ *hInstance,
|
|
Packit |
ae235b |
struct HINSTANCE__ *hPrevInstance,
|
|
Packit |
ae235b |
char *lpszCmdLine,
|
|
Packit |
ae235b |
int nCmdShow)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
char buf[100];
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if (__argc >= 2 && strcmp (__argv[1], "nop") == 0)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
sprintf (buf, "spawn-test-win32-gui: argv[0]=\"%s\"", __argv[0]);
|
|
Packit |
ae235b |
MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
else if (__argc <= 2)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
MessageBox (NULL, "spawn-test-win32-gui: Will write to stdout",
|
|
Packit |
ae235b |
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
printf ("This is stdout\n");
|
|
Packit |
ae235b |
fflush (stdout);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
MessageBox (NULL, "spawn-test-win32-gui: Will write to stderr",
|
|
Packit |
ae235b |
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
fprintf (stderr, "This is stderr\n");
|
|
Packit |
ae235b |
fflush (stderr);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
else if (__argc == 4 && strcmp (__argv[1], "pipes") == 0)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
int infd = atoi (__argv[2]);
|
|
Packit |
ae235b |
int outfd = atoi (__argv[3]);
|
|
Packit |
ae235b |
int k, n;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if (infd < 0 || outfd < 0)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
MessageBox (NULL, "spawn-test-win32-gui: illegal fds on command line",
|
|
Packit |
ae235b |
lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
exit (1);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
MessageBox (NULL, "spawn-test-win32-gui: Will write to parent",
|
|
Packit |
ae235b |
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
n = strlen ("Hello there");
|
|
Packit |
ae235b |
if (write (outfd, &n, sizeof (n)) == -1 ||
|
|
Packit |
ae235b |
write (outfd, "Hello there", n) == -1)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
int errsv = errno;
|
|
Packit |
ae235b |
sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errsv));
|
|
Packit |
ae235b |
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
exit (1);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
MessageBox (NULL, "spawn-test-win32-gui: Will read from parent",
|
|
Packit |
ae235b |
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if ((k = read (infd, &n, sizeof (n))) != sizeof (n))
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
sprintf (buf, "spawn-test-win32-gui: Got only %d bytes, wanted %d",
|
|
Packit |
ae235b |
k, sizeof (n));
|
|
Packit |
ae235b |
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
exit (1);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
sprintf (buf, "spawn-test-win32-gui: Parent says %d bytes to read", n);
|
|
Packit |
ae235b |
MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
if ((k = read (infd, buf, n)) != n)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
int errsv = errno;
|
|
Packit |
ae235b |
if (k == -1)
|
|
Packit |
ae235b |
sprintf (buf, "spawn-test-win32-gui: Read: %s", strerror (errsv));
|
|
Packit |
ae235b |
else
|
|
Packit |
ae235b |
sprintf (buf, "spawn-test-win32-gui: Got only %d bytes", k);
|
|
Packit |
ae235b |
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
exit (1);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
MessageBox (NULL, "spawn-test-win32-gui: Will write more to parent",
|
|
Packit |
ae235b |
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
n = strlen ("See ya");
|
|
Packit |
ae235b |
if (write (outfd, &n, sizeof (n)) == -1 ||
|
|
Packit |
ae235b |
write (outfd, "See ya", n) == -1)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
int errsv = errno;
|
|
Packit |
ae235b |
sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errsv));
|
|
Packit |
ae235b |
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
exit (1);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Sleep (2000);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
MessageBox (NULL, "spawn-test-win32-gui: Done, exiting.",
|
|
Packit |
ae235b |
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return 0;
|
|
Packit |
ae235b |
}
|