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
{{ message }}
Repository navigation
Impossible to both inherit the stderr/stdout and collect the exit code of the subprocess #12643
Also when I experimented with it, the LAST_EXIT_CODE seemed to point to the previously executed command in the REPL instead of the prev. statement. See the following, here the LAST_EXIT_CODE was 1 because prev. REPL command was a syntax error
@fdncred the main point is to inherit the stdout/stderr - not capture it, meaning stdout/stderr must be propagated to the current process that spawned the child process. For example, when I spawn terraform apply I want to see its logs in real time, because it takes a lot of time time to run and also reports its progress on stdout/stderr. But I also want to know its exit to code to figure out if it failed or not.
One of the problems is that --redirect-stdout/stderr parameters became deprecated in run-external, and behavior of capturing the stdout/stderr became implicit, and I can't opt out of it.
@Veetaha I made a PR that would allow you to get the exit code in a catch block if the external command fails. In the future, there will hopefully be a rework of I/O redirection and/or exit codes that should make this more intuitive and reliable.
The exit code is available as $e.exit_code in catch since #12648. try { ^bash -c "exit 3" }; $env.LAST_EXIT_CODE without a catch still gives 0 on 0.117.
Activity
fdncred commentedon Apr 24, 2024
I think maybe I'm missing the point here. What's not working?
Veetaha commentedon Apr 24, 2024
@fdncred the main point is to inherit the stdout/stderr - not capture it, meaning stdout/stderr must be propagated to the current process that spawned the child process. For example, when I spawn
terraform applyI want to see its logs in real time, because it takes a lot of time time to run and also reports its progress on stdout/stderr. But I also want to know its exit to code to figure out if it failed or not.One of the problems is that
--redirect-stdout/stderrparameters became deprecated inrun-external, and behavior of capturing thestdout/stderrbecame implicit, and I can't opt out of it.fdncred commentedon Apr 24, 2024
I think it's this PR #11934 that changed that part. @IanManske Any ideas how to help out here?
There's also a tee command that may help #11928
This PR also explains some new functionality with redirection for externals #11708
IanManske commentedon Apr 24, 2024
@Veetaha I made a PR that would allow you to get the exit code in a
catchblock if the external command fails. In the future, there will hopefully be a rework of I/O redirection and/or exit codes that should make this more intuitive and reliable.Make exit code available in `catch` block (#12648)
Make exit code available in `catch` block (nushell#12648)
fix(nushell): enable stdout piping for `list` while preserving direct…
kronberger-droid commentedon Nov 14, 2026
The exit code is available as
$e.exit_codeincatchsince #12648.try { ^bash -c "exit 3" }; $env.LAST_EXIT_CODEwithout acatchstill gives0on 0.117.