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 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.
The text was updated successfully, but these errors were encountered:
Perhaps one way to go about this could be to have Cmd::run return Result<ExitStatus> instead of Result<()>? This wouldn't really change anything about the default case of running with inherited IO streams and failing if the command fails (the ExitCode would still not be available in the Err case, but ? would propagate the execution failure), but when more granularity is needed it would allow using ignore_status to get an Ok(ExitStatus) which just says that the command was executed with some result, not that it returned 0.
This would let users explicitly opt in to the responsibility of checking for success via ignore_status and allow checking the result code, without impacting the (reasonable) default of run failing if the executed command fails.
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 whatCmd::run
will do by makingstdout
andstderr
inherited. However, I also want to look at the exit code of thexshell
Command to check why it failed (if it failed).Currently,
Cmd::run
returns aResult
withxshell::Error
in theErr
case, which is... very opaque (it basically just implementsError
, so you can print it out). The containedErrorKind
does have a VariantCmdStatus { cmd: CmdData, status: ExitStatus }
which you get ifcheck_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 theOutput
and the containedExitStatus
and then re-emitting theOutput
'sstdout
andstderr
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, sinceCmd::output
callsoutput_impl(true, true)
directly.The text was updated successfully, but these errors were encountered: