You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am spawning a command and forwarding streams to text readers. I thought I could additionally retrieve the standard output, even though it has been forwarder, from the command result. However doing so raises an ObjectDisposedException.
Medallion.Shell.Command shellCommand = Medallion.Shell.Command.Run(
executable: command.Program,
arguments: command.ArgumentValues,
options: opt =>
{
opt.Syntax(new NullSyntax());
});
shellCommand = shellCommand.RedirectStandardErrorTo(Console.Error);
shellCommand = shellCommand.RedirectTo(outputWriter);
shellCommand.Wait();
Medallion.Shell.CommandResult result = shellCommand.Result;
// ObjectDisposedException - cannot read from a closed text reader.
var r = result.StandardOutput;
The work around I found was to forward the standard output to another StringWriter and build the output from there.
The text was updated successfully, but these errors were encountered:
@Brice-xCIT this behavior is by-design, although it would be nice if we threw a clearer error message and perhaps (I'd have to think more about this) result.StandardOutput should return empty string rather than throwing.
Basically when you get output from a command it runs in one of two modes. Either the output fills a buffer and then gets collected in the result at the end OR the user decides to pipe the output to some other place in which case we no longer buffer it.
This behavior is important for performance. If you are running a process that is streaming a ton of data through standard out, you don't want to buffer it all in memory as a giant string. OTOH, for the simple case where standard output is just some diagnostic info then the result property is generally sufficient.
As a side note, I'm curious about what you're trying to do with NullSyntax. With the latest version of MedallionShell, I believe it should encode arguments correctly on all OS's/frameworks. What made you feel like you needed to move away from this?
I am spawning a command and forwarding streams to text readers. I thought I could additionally retrieve the standard output, even though it has been forwarder, from the command result. However doing so raises an ObjectDisposedException.
The work around I found was to forward the standard output to another StringWriter and build the output from there.
The text was updated successfully, but these errors were encountered: