Difficult (not possible?) to redirect binary output between Linux processes
A common pattern in Linux is to pipe output between commands. And such output is not always text (e.g., imagine a series of openssl commands). Unfortunately, the System.Diagnostic.Process class assumes that output and input is textual. Such an assumption violates Linux conventions.
@brendandixon Can you elaborate on your requirements, a small repro or code snippet of the scenario will help.
Are you suggesting the standardoutput/input/error should support binarystream, please provide an api proposal.
@Priya91 I apologize for being slow to respond. One case I encountered involves openssl. I need to run content through two openssl commands. The first emits a binary stream the second consumes as input. Sadly, I cannot do that via two Process objects (which would seem to be the natural .NET approach). Instead, I have a single process that shells to bash and pipes the output. I tried many setting variations before giving up.
@brendandixon The StandardOutput is a StreamReader, and it has BaseStream property which returns the underlying Stream. You can read this BaseStream with a BinaryReader. Will that work with your scenario?
Despite the above roundabout way, having a BinaryReader on Process output makes sense in x-plat context. We need an API proposal for this.
@Priya91 It's been a while since I've experimented, but I don't believe that worked. I was unable to obtain pure bytes; they get undergoing some degree of translation.
Triage: using StandardOutput.BaseStream should in principle provide an adequate workaround for handling non-textual data. I am going to close this, but assuming there are issues with that particular workaround we can take a closer look at those.