命令窗口
Posted pond-zzc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命令窗口相关的知识,希望对你有一定的参考价值。
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"));
以上是关于命令窗口的主要内容,如果未能解决你的问题,请参考以下文章