在MFC中如何獲取C:\命令提示符中輸出的反饋信息

熱心網(wǎng)友

這個問題我前天還在做呢,經(jīng)過1個星期的尋找,我找到了,是用window管道技術來做的。voidCDosWindowsDlg::OnButton1(){// ,hWrite;sa。nLength=sizeof(SECURITY_ATTRIBUTES);sa。lpSecurityDescriptor=NULL;sa。bInheritHandle=TRUE;if(!CreatePipe(&hRead,&hWrite,&sa,0)){MessageBox("ErrorOnCreatePipe()");return;}STARTUPINFOsi;PROCESS_INFORMATIONpi;si。cb=sizeof(STARTUPINFO);GetStartupInfo(&si);si。hStdError=hWrite;si。hStdOutput=hWrite;si。wShowWindow=SW_HIDE;si。dwFlags=STARTF_USESHOWWINDOW¦STARTF_USESTDHANDLES;if(!CreateProcess(NULL,"cmd。exe/cdir/?",NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)){MessageBox("ErroronCreateProcess()");return;}CloseHandle(hWrite);charbuffer[4096]={0};DWORDbytesRead;while(true){if(ReadFile(hRead,buffer,4095,&bytesRead,NULL)==NULL)break;m_Edit1+=buffer;//m_Edit1是CStringUpdateData(false);Sleep(200);}}。