StandardOutput and StandardError receive an extra line
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).
The extra line is null. Since applications cannot return null, my handlers can skip it. However, .NET should not be appending it.
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.