-
Notifications
You must be signed in to change notification settings - Fork 32
Description
I have a use case where I'm running some subcommands of a CLI tool using xshell that may take some time and so would like to have their output appear immediately on the terminal where the CLI tool was invoked. As far as I understand, this is what Cmd::run will do by making stdout and stderr inherited. However, I also want to look at the exit code of the xshell Command to check why it failed (if it failed).
Currently, Cmd::run returns a Result with xshell::Error in the Err case, which is... very opaque (it basically just implements Error, so you can print it out). The contained ErrorKind does have a Variant CmdStatus { cmd: CmdData, status: ExitStatus } which you get if check_status fails, but there's a Doc comment on that enum that says "Note: this is intentionally not public.".
What I'm currently doing is calling Cmd::output instead to get the Output and the contained ExitStatus and then re-emitting the Output's stdout and stderr manually. This works, but has the downside of introducing a very noticeable delay between running the subcommand and seeing it's output, since in particular the output doesn't show up "live" but instead only appears when the subcommand has either succeeded or failed. But I don't know how to change that, since Cmd::output calls output_impl(true, true) directly.