How to read output from cmd.exe using CreateProcess() and CreatePipe()

后端 未结 6 1829
盖世英雄少女心
盖世英雄少女心 2020-12-09 12:02

How to read output from cmd.exe using CreateProcess() and CreatePipe()

I have been trying to create a child process executing c

6条回答
  •  佛祖请我去吃肉
    2020-12-09 12:17

    I think you did everything right. But cmd.exe prints nothing or very little amount of data after start and your ReadFile blocks. If you move your cycle

    while (true) {
        bStatus = ReadFile(g_hChildStd_OUT_Rd, aBuf, sizeof(aBuf), &dwRead, NULL);
        if (!bStatus || dwRead == 0) {
            break;
        }
        aBuf[dwRead] = '\0';
        printf("%s\n", aBuf);
    }
    

    into background thread and run other cycle which will read your input and send it to cmd.exe, I think you can see any effect. Either you can make read buffer smaller (16 bytes e.g.).

提交回复
热议问题