diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/core/slang-process-util.cpp | 16 | ||||
| -rw-r--r-- | source/core/slang-process.h | 1 | ||||
| -rw-r--r-- | source/core/windows/slang-win-process.cpp | 13 |
3 files changed, 22 insertions, 8 deletions
diff --git a/source/core/slang-process-util.cpp b/source/core/slang-process-util.cpp index ef22c0392..99c81ee5c 100644 --- a/source/core/slang-process-util.cpp +++ b/source/core/slang-process-util.cpp @@ -57,7 +57,8 @@ static String _getText(const ConstArrayView<Byte>& bytes) const auto preCount = _getCount(outStdOut) + _getCount(outStdError); SLANG_RETURN_ON_FAIL(StreamUtil::readOrDiscard(stdOutStream, 0, outStdOut)); - SLANG_RETURN_ON_FAIL(StreamUtil::readOrDiscard(stdErrorStream, 0, outStdError)); + if (stdErrorStream) + SLANG_RETURN_ON_FAIL(StreamUtil::readOrDiscard(stdErrorStream, 0, outStdError)); const auto postCount = _getCount(outStdOut) + _getCount(outStdError); @@ -69,9 +70,16 @@ static String _getText(const ConstArrayView<Byte>& bytes) } // Read anything remaining - SLANG_RETURN_ON_FAIL(StreamUtil::readOrDiscardAll(stdOutStream, 0, outStdOut)); - SLANG_RETURN_ON_FAIL(StreamUtil::readOrDiscardAll(stdErrorStream, 0, outStdError)); - + for(;;) + { + const auto preCount = _getCount(outStdOut) + _getCount(outStdError); + StreamUtil::readOrDiscard(stdOutStream, 0, outStdOut); + if (stdErrorStream) + StreamUtil::readOrDiscard(stdErrorStream, 0, outStdError); + const auto postCount = _getCount(outStdOut) + _getCount(outStdError); + if (preCount == postCount) + break; + } return SLANG_OK; } diff --git a/source/core/slang-process.h b/source/core/slang-process.h index ab54f36c9..0beb78c06 100644 --- a/source/core/slang-process.h +++ b/source/core/slang-process.h @@ -23,6 +23,7 @@ public: { // Ignored on non-Windows platforms AttachDebugger = 0x01, + DisableStdErrRedirection = 0x02 }; }; diff --git a/source/core/windows/slang-win-process.cpp b/source/core/windows/slang-win-process.cpp index 93bff3eb3..e577da0fa 100644 --- a/source/core/windows/slang-win-process.cpp +++ b/source/core/windows/slang-win-process.cpp @@ -419,8 +419,11 @@ void WinProcess::kill(int32_t returnCode) WinHandle childStdInWriteTmp; // create stdout pipe for child process SLANG_RETURN_FAIL_ON_FALSE(CreatePipe(childStdOutReadTmp.writeRef(), childStdOutWrite.writeRef(), &securityAttributes, bufferSize)); - // create stderr pipe for child process - SLANG_RETURN_FAIL_ON_FALSE(CreatePipe(childStdErrReadTmp.writeRef(), childStdErrWrite.writeRef(), &securityAttributes, bufferSize)); + if ((flags & Process::Flag::DisableStdErrRedirection) == 0) + { + // create stderr pipe for child process + SLANG_RETURN_FAIL_ON_FALSE(CreatePipe(childStdErrReadTmp.writeRef(), childStdErrWrite.writeRef(), &securityAttributes, bufferSize)); + } // create stdin pipe for child process SLANG_RETURN_FAIL_ON_FALSE(CreatePipe(childStdInRead.writeRef(), childStdInWriteTmp.writeRef(), &securityAttributes, bufferSize)); @@ -431,7 +434,8 @@ void WinProcess::kill(int32_t returnCode) // create a non-inheritable duplicate of the stdout reader SLANG_RETURN_FAIL_ON_FALSE(DuplicateHandle(currentProcess, childStdOutReadTmp, currentProcess, childStdOutRead.writeRef(), 0, FALSE, DUPLICATE_SAME_ACCESS)); // create a non-inheritable duplicate of the stderr reader - SLANG_RETURN_FAIL_ON_FALSE(DuplicateHandle(currentProcess, childStdErrReadTmp, currentProcess, childStdErrRead.writeRef(), 0, FALSE, DUPLICATE_SAME_ACCESS)); + if (childStdErrReadTmp) + SLANG_RETURN_FAIL_ON_FALSE(DuplicateHandle(currentProcess, childStdErrReadTmp, currentProcess, childStdErrRead.writeRef(), 0, FALSE, DUPLICATE_SAME_ACCESS)); // create a non-inheritable duplicate of the stdin writer SLANG_RETURN_FAIL_ON_FALSE(DuplicateHandle(currentProcess, childStdInWriteTmp, currentProcess, childStdInWrite.writeRef(), 0, FALSE, DUPLICATE_SAME_ACCESS)); } @@ -522,7 +526,8 @@ void WinProcess::kill(int32_t returnCode) } RefPtr<Stream> streams[Index(StdStreamType::CountOf)]; - streams[Index(StdStreamType::ErrorOut)] = new WinPipeStream(childStdErrRead.detach(), FileAccess::Read); + if (childStdErrRead) + streams[Index(StdStreamType::ErrorOut)] = new WinPipeStream(childStdErrRead.detach(), FileAccess::Read); streams[Index(StdStreamType::Out)] = new WinPipeStream(childStdOutRead.detach(), FileAccess::Read); streams[Index(StdStreamType::In)] = new WinPipeStream(childStdInWrite.detach(), FileAccess::Write); |
