Skip to content

Cannot read from closed reader on result #58

@Brice-xCIT

Description

@Brice-xCIT

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions