1

我有免费的 glut 项目,其中包含计算 voronoy 网格、初始化 freeglut 然后绘制网格的代码。

pre-calculations
...
printf("Elapsed %lf seconds\n", (double)(clock() - start)/CLOCKS_PER_SEC);
glutInit            ( &argc, argv );
glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize  ( WIDTH, HEIGHT );

// create window
glutCreateWindow ( "Voronoy" );

// register handlers
glutDisplayFunc  ( display );
glutReshapeFunc  ( reshape );
glutKeyboardFunc ( key     );


glutMainLoop ();


return 0;
...

所以程序在控制台模式下工作,然后创建 freeglut 窗口。而且我还有一个单独的程序,它从连接到这个的标准输出管道中读取。我用这个参数创建过程

STARTUPINFO        si;

ZeroMemory(&si, sizeof(si));

si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdInput = stdinput.ReadPipe();
si.hStdOutput = stdoutput.WritePipe();
si.hStdError = stderror.WritePipe();
stdoutput.DuplicateReadPipe();

if ( !CreateProcess( "j:\\Projects\\study\\fortune\\Debug\\voronoy.exe",//"C:\\GnuWin32\\bin\\ls.exe",
    NULL,
    NULL, NULL,
    TRUE,
    (CREATE_SUSPENDED | CREATE_SEPARATE_WOW_VDM | CREATE_NO_WINDOW),
    NULL, NULL,
    &si, &process_info) )
{
    throw("!!!");
}
DWORD w = ResumeThread(process_info.hThread);
CloseHandle(process_info.hProcess);
CloseHandle(process_info.hThread);

而且我还尝试了 MSDN 中的标准管道示例。

问题是程序没有从管道接收数据。我也试过 voronoy.exe > test.txt 在 cmd.exe 和 test.txt 仍然是空的。但是如果我在没有管道的情况下运行它 - 它工作正常,我可以在控制台中看到输出。

4

1 回答 1

2

答案很简单。我需要通过简单地调用来刷新标准输出

fflush(stdout);
于 2012-07-10T22:52:05.827 回答