runtime icon indicating copy to clipboard operation
runtime copied to clipboard

StandardOutput and StandardError receive an extra line

Open brendandixon opened this issue 10 years ago • 2 comments

On Linux, compared to other languages, say Python, .NET is appending (somehow) an extra line on redirected StandardOutput and StandardError.

For example, if I execute the following script:

#!/bin/sh
exit 42

In Python (e.g., subprocess.check_output) I receive, as I would expect, an empty string. In .NET, however, if I redirect through ProcessStartInfo, I receive an event in my OutputDataReceived handler with an empty string (and the my code cannot reject empty string out-of-hand since it may be a legal part of output).

brendandixon avatar Aug 01 '16 22:08 brendandixon

The extra line is null. Since applications cannot return null, my handlers can skip it. However, .NET should not be appending it.

brendandixon avatar Aug 02 '16 18:08 brendandixon

However, .NET should not be appending it.

Discussed with @terrajobst on why we have null to indicate last write instead of event trigger. This design aligns with other apis, such as StreamReader which uses null to indicate the end of stream, and is also documented here. The user callback should scan for the null line to determine end of output/error stream.

Priya91 avatar Aug 24 '16 00:08 Priya91