MFC 应用程序中使用管道代码示意
 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);
本文来自博客园,作者:阳光雨露&,转载请注明原文链接:https://www.cnblogs.com/SunShineYPH/p/4482709.html
 
                     
                    
                 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号 
