Hi,

I have an app that works with Visual Studio 2010, but not with VS2015.

Its purpose is to redirect stdout to a thread that reads from a pipe created with:

  if (FALSE == CreatePipe(&pipeout, &pipein, &sec, 0))
   { mes = strdupa("SCRIPT: Unable to create pipe");
     goto err;
   }

  SetStdHandle(STD_OUTPUT_HANDLE, pipein);
  hCrt = _open_osfhandle((intptr_t)pipein, _O_TEXT|_O_APPEND );
  hf = _fdopen(hCrt, "r");
  *stdout = *hf;

The child thread reads the pipe with:

  char c;
  int rr;
  OVERLAPPED ov;

  for(;;)
   { bzero((char *)&ov, sizeof(OVERLAPPED));
     if (FALSE == ReadFile(pipeout, &c, 1, &rr, &ov ))
      { char *mes = wgle();
        ExitThread(1);
      }

If the main threads does either:

write(fileno(stdout), "test\n", 5);
WriteFile(pipein, "test2\n", 6, &flag, NULL);

the child reads these 2 strings with VS2010, but only the second with VS2015.

What I am doing wrong?

Thanks for any help...

I solved the problem by taking a completely different approach, that works with both V2010 and V2015.

To summarize, I use only Posix calls to redirect and to pipe, like close(fileno(stdout)) followed by dup(pipe[1]), and the child opens a new handle to the console to write to stdout after processing the data read from the pipe.

This article has been dead for over six months. Start a new discussion instead.