mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-29 13:20:54 +00:00
os: Update LaunchProcess to consume all stdout before checking stderr
For commands that write to stdout multiple times before writing stderr, the second ReadFile would hang indefinitely. This was seen using "adb pull" with a sufficiently large APK (~20MB).
This commit is contained in:
committed by
Baldur Karlsson
parent
e0dfdedb24
commit
c735a30750
@@ -455,18 +455,21 @@ uint32_t Process::LaunchProcess(const char *app, const char *workingDir, const c
|
||||
result->strStderror = "";
|
||||
|
||||
ssize_t stdoutRead, stderrRead;
|
||||
char chBuf[4096];
|
||||
do
|
||||
{
|
||||
char chBuf[1000];
|
||||
stdoutRead = read(stdoutPipe[0], chBuf, sizeof(chBuf));
|
||||
if(stdoutRead > 0)
|
||||
result->strStdout += string(chBuf, stdoutRead);
|
||||
} while(stdoutRead > 0);
|
||||
|
||||
do
|
||||
{
|
||||
stderrRead = read(stderrPipe[0], chBuf, sizeof(chBuf));
|
||||
if(stderrRead > 0)
|
||||
result->strStderror += string(chBuf, stderrRead);
|
||||
|
||||
} while(stdoutRead > 0 || stderrRead > 0);
|
||||
} while(stderrRead > 0);
|
||||
|
||||
// Close read ends.
|
||||
close(stdoutPipe[0]);
|
||||
|
||||
@@ -925,20 +925,28 @@ uint32_t Process::LaunchProcess(const char *app, const char *workingDir, const c
|
||||
{
|
||||
result->strStdout = "";
|
||||
result->strStderror = "";
|
||||
|
||||
char chBuf[4096];
|
||||
DWORD dwOutputRead, dwErrorRead;
|
||||
BOOL success = FALSE;
|
||||
string s;
|
||||
for(;;)
|
||||
{
|
||||
char chBuf[1000];
|
||||
DWORD dwOutputRead, dwErrorRead;
|
||||
|
||||
BOOL success = ReadFile(hChildStdOutput_Rd, chBuf, sizeof(chBuf), &dwOutputRead, NULL);
|
||||
string s(chBuf, dwOutputRead);
|
||||
success = ReadFile(hChildStdOutput_Rd, chBuf, sizeof(chBuf), &dwOutputRead, NULL);
|
||||
s = string(chBuf, dwOutputRead);
|
||||
result->strStdout += s;
|
||||
|
||||
if(!success && !dwOutputRead)
|
||||
break;
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
success = ReadFile(hChildStdError_Rd, chBuf, sizeof(chBuf), &dwErrorRead, NULL);
|
||||
s = string(chBuf, dwErrorRead);
|
||||
result->strStderror += s;
|
||||
|
||||
if(!success && !dwOutputRead && !dwErrorRead)
|
||||
if(!success && !dwErrorRead)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user