This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with pex-win32.c

Ross Ridge wrote:

> Why isn't there a console window?  The Cygwin version of rxvt, and I
> think xterm, creates (and keeps hidden) a console window that should
> be inherited by gcc and as.  If there wasn't console window for gcc to
> inherit, why didn't Windows create one for gcc?

I can't answer that.  I will, however, attach test test code I've used;
these are tiny programs, nothing to do with GCC.  Compiled as:

  i686-mingw32-gcc -o child.exe child.c
  i686-mingw32-gcc -o parent.exe parent.c

The child just prints a message.

The parent, based on the command line argument its given, invokes the
child in one of several ways; for example "parent spawn" uses spawnv to
invoke the child, while "parent std" uses CreateProcess, with the hStd*
handles filled in and START_USESTDHANDLES.

Here's a table showing what happens:

Cygwin Xterm
parent spawn: Pops up DOS window.
parent nostd: No output from child.
parent std:   Works.

DOS Console
parent spawn: Works.
parent nostd: No output from child.
parent std:   No output from child.

Mark Mitchell
(650) 331-3385 x713
#include <stdio.h>
#include <process.h>
#include <string.h>
#include <windows.h>

int main (int arcgc, char **argv) {
  fprintf (stderr, "Parent started\n");
  fflush (stderr);
  if (strcmp (argv[1], "spawn") == 0) {
    const char *const child_argv[2] = { "child.exe", NULL };
    spawnvp (_P_WAIT, "child.exe", child_argv);
  } else {
    si.cb = sizeof (si);
    si.lpReserved = NULL;
    si.lpDesktop = NULL;
    si.cbReserved2 = 0;
    si.lpReserved2 = NULL;
    if (strcmp (argv[1], "nostd") == 0) {
      si.dwFlags = 0;
    } else {
      si.dwFlags = STARTF_USESTDHANDLES;
      si.hStdInput = _get_osfhandle (0);
      si.hStdOutput = _get_osfhandle (1);
      si.hStdError = _get_osfhandle (2);
    if (!CreateProcess ("child.exe",
			&pi)) {
      fprintf (stderr, "Could not start child\n");
    } else {
      WaitForSingleObject(pi.hProcess, INFINITE);
  fprintf (stderr, "Parent done\n");
#include <stdio.h>

int main () {
  printf ("Child.\n");
  return 0;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]