重定向标准输出错误输出到编辑控件中!
来源:互联网 发布:怎样才能加入淘宝客 编辑:程序博客网 时间:2024/05/14 06:15
有时候我们需要重定向标准输出(stdout)错误输出(stderr)到编辑控件中:
比如我们作了一个前端编译器,编译的功能由mingw gcc来完成,这时我们要捕获它的编译消息到我们的输出窗口,这时怎么办呢!
很简单,我们需要用匿名管道来实现,参见如下代码:
SECURITY_ATTRIBUTES g_sa = {sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};void CGccDbgView::OnCompiler() {// TODO: Add your control notification handler code hereHANDLE hWritePipe, hReadPipe;if ( !CreatePipe( &hReadPipe, &hWritePipe, &g_sa, 0 ) ){return;}CString strCmdLine="c:\\gcc.exe test.c";// create an environment for the CGI process....DWORD dwCreateFlags = 0;PROCESS_INFORMATION pi;STARTUPINFO si = {0};si.cb = sizeof(si);si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;si.wShowWindow = SW_HIDE;si.hStdInput = hReadPipe;si.hStdOutput = hWritePipe;si.hStdError = hWritePipe;BOOL bOk = CreateProcess( NULL, strCmdLine.GetBuffer(1),NULL, NULL, TRUE,dwCreateFlags, NULL,"c:\\", &si, &pi );strCmdLine.ReleaseBuffer();// if created....if ( bOk ){char buffer[1024]={0};// wait for either cancel or process done....WaitForSingleObject(pi.hProcess,INFINITE);// release our hold on the thread....CloseHandle( pi.hThread );// send the body of the post to the stdin....DWORD dwWritten = 0;ReadFile( hReadPipe, buffer,1024,&dwWritten, NULL );m_msg = buffer;//AfxMessageBox(m_msg);UpdateData(FALSE);// close our hold on it....CloseHandle( pi.hProcess );}}
这里m_msg属于编辑器控件变量。这样我们就能在编辑控件中看到结果了。如图:
- 重定向标准输出错误输出到编辑控件中!
- 将Linux 标准输出,错误输出重定向到文件
- shell 错误输出重定向到标准输出
- 重定向标准错误输出
- 重定向标准错误输出
- 重定向标准错误输出
- Linux重定向:将标准输出stdout和标准错误stderr重定向到一个文件
- linux 重定向 标准输入 标准输出 标准错误输出
- linux下重定向,把标准输出和错误输出一起同定向到文件
- 标准输入输出、错误输出、重定向标准输出
- 标准输入输出、错误输出、重定向标准输出
- shell将标准错误输出重定向为标准输出
- tcsh重定向标准输出和标准错误输出
- 标准输入输出、错误输出、重定向标准输出
- 标准输入输出、错误输出、重定向标准输出
- 将标准输出重定向到GUI
- 【转】标准输出重定向到GUI
- Java标准输出重定向到GUI
- 房价
- Android之自定义Adapter的ListView
- 用自己指定的模板创建ahk脚本
- jQuery MiniUI - 快速开发WebUI
- JSP指令-page、include、taglib指令
- 重定向标准输出错误输出到编辑控件中!
- 黑马程序员--解析XML的几种方法
- DM9000驱动理解三(中断函数)
- JPEG编解码过程详解
- 设计模式之装饰者模式
- git 笔记
- iphone开发基础
- exit abort return 区别
- Windows8/Silverlight/WPF/WP7/HTML5周学习导读(1月1日-1月6日)