zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    NOIP 2012 T5 借教室 [洛谷P1083]
    POJ2437 Muddy roads
    POJ2288 Islands and Bridges
    洛谷P2014 TYVJ1051 选课
    POJ1741 Tree
    CODEVS1995 || TYVJ1863 黑魔法师之门
    TYVJ1939 玉蟾宫
    TYVJ1305 最大子序和
    POJ1737 Connected Graph
    TYVJ1864 守卫者的挑战
  • 原文地址:https://www.cnblogs.com/SunShineYPH/p/4482709.html
Copyright © 2011-2022 走看看