Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tee? #70

Closed
yevhen opened this issue Apr 5, 2020 · 3 comments
Closed

Tee? #70

yevhen opened this issue Apr 5, 2020 · 3 comments
Labels

Comments

@yevhen
Copy link

yevhen commented Apr 5, 2020

I'm trying to find a way to use Command as a tee, so it's both outputs to writer (console) and returns standard output as result. Is that possible with current API?

@madelson
Copy link
Owner

Hi @yevhen there isn't currently a way to both have it retain the buffered content and stream it out to console. However, it shouldn't be too difficult to do this yourself:

var teeTextWriter = new TeeTextWriter();

await Command.Run(...).RedirectTo(teeTextWriter).Task; // will print to stdout
var output = teeTextWriter.ToString();

private class TeeTextWriter : TextWriter
{
    private readonly StringBuilder _stringBuilder = new StringBuilder();

    public override void Write(char ch)
    {
        this._stringBuilder.Append(ch);
        Console.Out.Write(ch);
    }

    public override string ToString() => this._stringBuilder.ToString();
}

@madelson
Copy link
Owner

Filed #71 as a potential enhancement request for the future.

@yevhen
Copy link
Author

yevhen commented Apr 12, 2020

@madelson ye, thanks! I did something very similar ))

BTW, thanks for the great project!

@yevhen yevhen closed this as completed Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants