STARTUPINFO sinf = {0};
PROCESS_INFORMATION pinf = {0};
SECURITY_ATTRIBUTES sa = {0};
HANDLE hPipeORead = NULL;
HANDLE hPipeOWrite = NULL;
HANDLE hPipeIRead = NULL;
HANDLE hPipeIWrite = NULL;

sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;

CreatePipe(&hPipeORead, &hPipeOWrite, &sa, 0);
CreatePipe(&hPipeIRead, &hPipeIWrite, &sa, 0);

sinf.cb = sizeof(sinf);
sinf.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
sinf.wShowWindow = SW_HIDE;
sinf.hStdInput = hPipeIRead;
sinf.hStdOutput = hPipeOWrite;
sinf.hStdError = hPipeOWrite;

char szBuf[] = {"python \"E:\\WorkSpace\\TestData\\iLog\\utils_ilog_info_from_bugzilla_id.py\" 432686"};
if (!CreateProcess(NULL, szBuf, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &sinf, &pinf))
{
MessageBox("Create Process Error!");
return;
}

std::auto_ptr<BYTE> spBuf(new BYTE[1024 * 512]); // 512K
DWORD dwReadBytes = 0;
if (!ReadFile(hPipeORead, spBuf.get(), 1024 * 512, &dwReadBytes, NULL))
{
CloseHandle(hPipeOWrite);
CloseHandle(hPipeORead);

CloseHandle(hPipeIWrite);
CloseHandle(hPipeIRead);
return;
}

CString strResult((char*)spBuf.get());

CloseHandle(hPipeOWrite);
CloseHandle(hPipeORead);

CloseHandle(hPipeIWrite);
CloseHandle(hPipeIRead);

相关文章:

  • 2022-12-23
  • 2021-07-26
  • 2022-03-14
  • 2021-11-12
  • 2022-12-23
  • 2021-07-16
  • 2021-10-21
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-12-16
  • 2021-10-25
  • 2022-12-23
相关资源
相似解决方案