• getting exit status from a pipe

    From Roger Oberholtzer@21:1/5 to All on Fri May 5 04:00:03 2023
    See $subject.

    I run a command as:

    set cmd [open "|command"]

    Eventually, I close it. As one does.

    How do I get the exit status (?$ in bash or %errorlevel% in dos) from 'command'? In the samples I see, they use:

    catch {close $cmd} results options

    The claim is that this should contain the information from the command run in the pipe.

    I do not seem to get this. I'm testing on Windows.

    If I run 'command' at the prompt, I see that it exits with, say, 5 (which makes sense for the command). What I get in the results is a code of 1, and typically something like "command exited unexpectedly". I do not see it doing that when run directly.

    Have I missed some critical point?

    The reason I am doing it as a pipe is that it can be a very long running command, and I want the Tcl program that calls it to still be active. And I want access to whatever it prints. That part is working. It seem to properly detect when the pipe is
    closed (eof $cmd).

    I'm basing my code on

    https://wiki.tcl-lang.org/page/Execute+in+Parallel+and+Wait

    Aside from getting the exit status, the code seems to work. Except I think the "catch [close $cmd] r o" should use curly brackets. I did try that to see if there was some voodoo thing going on. It made no difference.

    Can I get the exit status of the command somehow?



    --
    Roger

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Roger Oberholtzer@21:1/5 to Roger Oberholtzer on Fri May 5 05:34:32 2023
    On Friday, May 5, 2023 at 1:00:07 PM UTC+2, Roger Oberholtzer wrote:
    See $subject.

    I run a command as:

    set cmd [open "|command"]

    Eventually, I close it. As one does.

    How do I get the exit status (?$ in bash or %errorlevel% in dos) from 'command'? In the samples I see, they use:

    catch {close $cmd} results options

    The claim is that this should contain the information from the command run in the pipe.

    I do not seem to get this. I'm testing on Windows.

    If I run 'command' at the prompt, I see that it exits with, say, 5 (which makes sense for the command). What I get in the results is a code of 1, and typically something like "command exited unexpectedly". I do not see it doing that when run directly.

    Have I missed some critical point?

    The reason I am doing it as a pipe is that it can be a very long running command, and I want the Tcl program that calls it to still be active. And I want access to whatever it prints. That part is working. It seem to properly detect when the pipe is
    closed (eof $cmd).

    I'm basing my code on

    https://wiki.tcl-lang.org/page/Execute+in+Parallel+and+Wait

    Aside from getting the exit status, the code seems to work. Except I think the "catch [close $cmd] r o" should use curly brackets. I did try that to see if there was some voodoo thing going on. It made no difference.

    Can I get the exit status of the command somehow?

    Ok. Bad form answering your own question. But I see that if the -code is 1 (TCL_ERROR) one should look at -errorcode for more information. I knew this from the mists of time. Anyway, if I look there I find what I am looking for.

    Thanks Roger for that splendid answer!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)