Tyrrrz / CliWrap

Library for running command-line processes
MIT License
4.32k stars 264 forks source link

Can STDIN fake being a TTY? #154

Closed chris-findlay closed 2 years ago

chris-findlay commented 2 years ago

Details

Some commands (e.g. ls or docker) output differently based on the result of calling isatty(3), e.g. different formats or using cursor control escape codes to keep the output tidy.

Is there any way to get a process run from .Net to get a true answer from that check so it thinks it's outputting to a terminal?

I really like the look of this lib, but if it can manage the above, then switching to it will be an easy sell. (c:

chris-findlay commented 2 years ago

...for that matter, can .Net tell if it's connected to a TTY for output?

Tyrrrz commented 2 years ago

I know most .NET programs use Console.IsOutputRedirected to check if they are in a terminal. When running a process with CliWrap, the output of that property will be true. You can fake a terminal by wrapping it instead -- i.e. instead of Cli.Wrap("foo") do Cli.Wrap("/bin/sh").WithArguments(...). In this case, the output of the underlying process (launched by sh) will not be considered redirected.

chris-findlay commented 2 years ago

Now that you mention it, that seems obvious - thanks heaps.