DWORD readProcessStream()

in src/main/cpp/launcher/windows/src/ProcessUtils.c [59:80]


DWORD readProcessStream(PROCESS_INFORMATION pi, HANDLE currentProcessStdin, HANDLE currentProcessStdout, HANDLE currentProcessStderr, DWORD timeOut, HANDLE hWriteInput, HANDLE hWriteOutput, HANDLE hWriteError) {
    DWORD started = GetTickCount();
    WCHAR buf[STREAM_BUF_LENGTH];
    DWORD exitCode=0;    
    DWORD outRead =0;
    DWORD errRead =0;
    DWORD inRead =0;
    while(1) {
        outRead = readNextData(currentProcessStdout, buf, hWriteOutput);
        errRead = readNextData(currentProcessStderr, buf, hWriteError);
        inRead  = readNextData(hWriteInput, buf, currentProcessStdin);
        GetExitCodeProcess(pi.hProcess, &exitCode);
        if (exitCode != STILL_ACTIVE) break;
        
        if(outRead == 0 && errRead==0 && inRead==0 && timeOut!=INFINITE) {
            if((GetTickCount() - started) > timeOut) break;
        }
        //avoid extra using of CPU resources
        Sleep(1);
    }
    return exitCode;
}