创建管道
std::string sLog;
HANDLE hRead1, hWrite1, hRead2, hWrite2;
SECURITY_ATTRIBUTES sat;
sat.nLength = sizeof(SECURITY_ATTRIBUTES);
sat.bInheritHandle = true;
sat.lpSecurityDescriptor = nullptr;
if(!CreatePipe(&hRead1,&hWrite1,&sat,0))
{
sLog = "管道1创建失败...";
return false;
}
if(!CreatePipe(&hRead2,&hWrite2,&sat,0))
{
sLog = "管道2创建失败...";
CloseHandle(hRead1);
CloseHandle(hWrite1);
return false;
}
创建进程并重定向
STARTUPINFO startupinfo;
startupinfo.cb = sizeof(STARTUPINFO);
GetStartupInfo(&startupinfo);
startupinfo.hStdError = hWrite2;
startupinfo.hStdOutput = hWrite2;
startupinfo.hStdInput = hRead1;
startupinfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
startupinfo.wShowWindow = SW_HIDE;
PROCESS_INFORMATION pinfo;
std::string sCmd =