You don't need special tricks.
Tested: When you start a GUI application with standard io redirected to pipes, they work just like in console application:
test.bat
@echo off
gui.exe | find /v "__nonexist__"
pause
output:
WriteFile
puts
child.c:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE h;
TCHAR tstr[100];
DWORD nb;
h = GetStdHandle(STD_OUTPUT_HANDLE);
_stprintf(tstr, _T("0x%08x"), h);
MessageBox(NULL, tstr, _T("x"), MB_OK);
#define sWriteFile "WriteFile\n"
#define sPuts "puts\n"
if (h) {
WriteFile(h, sWriteFile, sizeof(sWriteFile)-1, &nb, NULL);
fputs(sPuts, stdout);
}
return 0;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
return _tmain(0, NULL);
}
When you start a GUI program from console, standard handles are closed, but there's a way to reopen them. This trick is used in netbeans.exe