标签:sleep let ons tde message flags pipe out des
void CFileRenameDlg::_execute(const CString& cmd)
{
SECURITY_ATTRIBUTES sa;
HANDLE hRead,hWrite;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if(!CreatePipe(&hRead,&hWrite,&sa,0))
{
MessageBox(_T("启动失败"));
return;
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si,sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdError = hWrite;
si.hStdOutput = hWrite;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
CString sCmd = _T("cmd /c \"") + cmd + _T("\"");
TCHAR* szCmd = new TCHAR[sCmd.GetLength() + 1];
_tcscpy(szCmd, sCmd.GetString());
if(!CreateProcess(NULL, szCmd, NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
{
MessageBox(_T("启动失败"));
delete[] szCmd;
return;
}
delete[] szCmd;
CloseHandle(hWrite);
char buffer[4096] = {0};
CString strOutput;
DWORD bytesRead;
while(1)
{
if(NULL == ReadFile(hRead,buffer,4095,&bytesRead,NULL))
{
break;
}
strOutput += buffer;
Sleep(1000);
}
CloseHandle(hRead);
}
test:
_execute(_T("D:\\test.csv"));
标签:sleep let ons tde message flags pipe out des
原文地址:https://www.cnblogs.com/Pond-ZZC/p/13036782.html