Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Being overloaded is the sign of a true Debian maintainer. -- JHM on #Debian


devel / comp.lang.tcl / Re: getting exit status from a pipe

SubjectAuthor
* getting exit status from a pipeRoger Oberholtzer
`- Re: getting exit status from a pipeRoger Oberholtzer

1
getting exit status from a pipe

<10dd8528-f150-4bd6-b86a-4ff4211028d6n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21952&group=comp.lang.tcl#21952

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:f07:b0:74d:dcc:c9b7 with SMTP id v7-20020a05620a0f0700b0074d0dccc9b7mr182838qkl.0.1683284404378;
Fri, 05 May 2023 04:00:04 -0700 (PDT)
X-Received: by 2002:a05:622a:1a05:b0:3ed:54d:629e with SMTP id
f5-20020a05622a1a0500b003ed054d629emr373885qtb.13.1683284404109; Fri, 05 May
2023 04:00:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 5 May 2023 04:00:03 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=213.88.151.140; posting-account=2KzPfQoAAABsDx3yFmRtytkEMJAH7kkG
NNTP-Posting-Host: 213.88.151.140
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <10dd8528-f150-4bd6-b86a-4ff4211028d6n@googlegroups.com>
Subject: getting exit status from a pipe
From: roger.oberholtzer@gmail.com (Roger Oberholtzer)
Injection-Date: Fri, 05 May 2023 11:00:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2429
 by: Roger Oberholtzer - Fri, 5 May 2023 11:00 UTC

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

Re: getting exit status from a pipe

<35a406e9-6337-417e-97f0-6e4e0778be99n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21954&group=comp.lang.tcl#21954

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:25c9:b0:74d:fb3d:536 with SMTP id y9-20020a05620a25c900b0074dfb3d0536mr293798qko.13.1683290073054;
Fri, 05 May 2023 05:34:33 -0700 (PDT)
X-Received: by 2002:ad4:55c7:0:b0:61b:608b:d310 with SMTP id
bt7-20020ad455c7000000b0061b608bd310mr164038qvb.0.1683290072666; Fri, 05 May
2023 05:34:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 5 May 2023 05:34:32 -0700 (PDT)
In-Reply-To: <10dd8528-f150-4bd6-b86a-4ff4211028d6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=213.88.151.140; posting-account=2KzPfQoAAABsDx3yFmRtytkEMJAH7kkG
NNTP-Posting-Host: 213.88.151.140
References: <10dd8528-f150-4bd6-b86a-4ff4211028d6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <35a406e9-6337-417e-97f0-6e4e0778be99n@googlegroups.com>
Subject: Re: getting exit status from a pipe
From: roger.oberholtzer@gmail.com (Roger Oberholtzer)
Injection-Date: Fri, 05 May 2023 12:34:33 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3172
 by: Roger Oberholtzer - Fri, 5 May 2023 12:34 UTC

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!


devel / comp.lang.tcl / Re: getting exit status from a pipe

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor