【问题标题】:Cannot get stdoutput from freeGlut project无法从 freeGlut 项目中获取标准输出
【发布时间】:2012-07-10 06:30:32
【问题描述】:

我有一个免费的 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 仍然是空的。 但如果我在没有管道的情况下运行它 - 它工作正常,我可以在控制台中看到输出。

【问题讨论】:

    标签: c++ windows winapi pipe freeglut


    【解决方案1】:

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

    fflush(stdout);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-25
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      • 2020-11-28
      • 2017-11-06
      • 1970-01-01
      • 2017-12-29
      相关资源
      最近更新 更多