代码
STARTUPINFO si; // 启动信息
PROCESS_INFORMATION pi; // 进程信息
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si); //取得当前进程的StartupInfo,并根据当前进程进行修改
si.hStdError = hWrite; //错误输出
si.hStdOutput = hWrite; //标准输出
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
CString strCmdLine ="cmd" ;
//创建子进程
if (!CreateProcess(NULL, strCmdLine.GetBuffer(),NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
{
MessageBox( "创建进程失败!");
return;
}
CloseHandle(hWrite);
Sleep(200);
char buffer[4096] = {0};
DWORD bytesRead;
while (true)
{
if (ReadFile(hRead,buffer,4095,&bytesRead,NULL) == NULL)
break;
CString strInfo;
GetDlgItemText(IDC_EDIT_Info,strInfo);
strInfo += buffer;
SetDlgItemText(IDC_EDIT_Info,strInfo);
//TRACE(buffer);
}
CloseHandle(hRead);
PROCESS_INFORMATION pi; // 进程信息
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si); //取得当前进程的StartupInfo,并根据当前进程进行修改
si.hStdError = hWrite; //错误输出
si.hStdOutput = hWrite; //标准输出
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
CString strCmdLine ="cmd" ;
//创建子进程
if (!CreateProcess(NULL, strCmdLine.GetBuffer(),NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
{
MessageBox( "创建进程失败!");
return;
}
CloseHandle(hWrite);
Sleep(200);
char buffer[4096] = {0};
DWORD bytesRead;
while (true)
{
if (ReadFile(hRead,buffer,4095,&bytesRead,NULL) == NULL)
break;
CString strInfo;
GetDlgItemText(IDC_EDIT_Info,strInfo);
strInfo += buffer;
SetDlgItemText(IDC_EDIT_Info,strInfo);
//TRACE(buffer);
}
CloseHandle(hRead);