Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Don't panic.


devel / comp.lang.tcl / Re: command pipes: puts vs. return

SubjectAuthor
* command pipes: puts vs. returnsaitology9
+* Re: command pipes: puts vs. returnmango
|`* Re: command pipes: puts vs. returnsaitology9
| `- Re: command pipes: puts vs. returnheinrichmartin
`- Re: command pipes: puts vs. returnChristian Gollwitzer

1
command pipes: puts vs. return

<t6emf1$bok$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.91.POSTED!not-for-mail
From: saitology9@gmail.com
Newsgroups: comp.lang.tcl
Subject: command pipes: puts vs. return
Date: Sun, 22 May 2022 21:02:24 -0400
Organization: Aioe.org NNTP Server
Message-ID: <t6emf1$bok$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="12052"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: saitology9@gmail.com - Mon, 23 May 2022 01:02 UTC

Hello,

I have a question on the internal processing of command pipes in Tcl.
When you open a command pipe via [open "|..."' r+] and run a tcl script,
the output is available as long as you use "puts" statements in the
code. However, if instead you return a value as the last command in the
script, that return value is lost.

Is there a way to capture the returns instead, or both?

More details:

I am reading the book The Tcl Programming Language, chapter 16 on pipes,
i.e., the construct known as [open "|..."].

So I wrote a simple script and saved it in a file as follows:

file name: c:/temp/sample.tcl
file data: puts "Current time: [clock format [clock seconds]]"

Following the advice there, I can call it like so:

set chan [open "|[list [info nameofexecutable]] C:/temp/sample.tcl" r+]
chan configure $chan -buffering line
gets $chan

And I can see the the printed output. However, if I change the
sample.tcl as follows,

return "Current time: [clock format [clock seconds]]"

then nothing is read from the channel.

Re: command pipes: puts vs. return

<a68b6e2d-53f1-4d8d-8673-8175730fc305n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:27cd:b0:6a3:756f:8267 with SMTP id i13-20020a05620a27cd00b006a3756f8267mr3369722qkp.374.1653269057051;
Sun, 22 May 2022 18:24:17 -0700 (PDT)
X-Received: by 2002:a05:6870:328a:b0:f2:4cf4:f17c with SMTP id
q10-20020a056870328a00b000f24cf4f17cmr2801920oac.211.1653269056655; Sun, 22
May 2022 18:24:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.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: Sun, 22 May 2022 18:24:16 -0700 (PDT)
In-Reply-To: <t6emf1$bok$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=24.176.163.173; posting-account=ZFot6woAAABKx26r18WnGS2aDcK8wnRB
NNTP-Posting-Host: 24.176.163.173
References: <t6emf1$bok$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a68b6e2d-53f1-4d8d-8673-8175730fc305n@googlegroups.com>
Subject: Re: command pipes: puts vs. return
From: amangogna@modelrealization.com (mango)
Injection-Date: Mon, 23 May 2022 01:24:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2078
 by: mango - Mon, 23 May 2022 01:24 UTC

On Sunday, May 22, 2022 at 6:02:30 PM UTC-7, saito...@gmail.com wrote:
> Hello,
>
[snip]

> Following the advice there, I can call it like so:
>
> set chan [open "|[list [info nameofexecutable]] C:/temp/sample.tcl" r+]
> chan configure $chan -buffering line
> gets $chan
>
> And I can see the the printed output. However, if I change the
> sample.tcl as follows,
>
> return "Current time: [clock format [clock seconds]]"
>
> then nothing is read from the channel.

I'm not sure what you expectation is here. The original script opens a pipeline to read the standard output of a process as if it were a file. When the original script writes to the standard output (using puts), then indeed the output is seen. When you change the script to omit generating standard output, then you seen nothing. That's sorta what I would expect. Not clear to me what your expectations were.

Re: command pipes: puts vs. return

<t6eo7p$qsv$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.91.POSTED!not-for-mail
From: saitology9@gmail.com
Newsgroups: comp.lang.tcl
Subject: Re: command pipes: puts vs. return
Date: Sun, 22 May 2022 21:32:40 -0400
Organization: Aioe.org NNTP Server
Message-ID: <t6eo7p$qsv$1@gioia.aioe.org>
References: <t6emf1$bok$1@gioia.aioe.org>
<a68b6e2d-53f1-4d8d-8673-8175730fc305n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="27551"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9@gmail.com - Mon, 23 May 2022 01:32 UTC

On 5/22/22 9:24 PM, mango wrote:
>
> I'm not sure what you expectation is here. The original script opens a pipeline to read the standard output of a process as if it were a file. When the original script writes to the standard output (using puts), then indeed the output is seen. When you change the script to omit generating standard output, then you seen nothing. That's sorta what I would expect. Not clear to me what your expectations were.
>
>

Hello,

I was interested in capturing the return value, but using the spawning
mechanism. But I see what you mean. Thank you.

Re: command pipes: puts vs. return

<8c415927-e572-44ca-a4ae-87f21f84853bn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:29ce:b0:462:3e67:bdcd with SMTP id gh14-20020a05621429ce00b004623e67bdcdmr2471060qvb.94.1653285645299;
Sun, 22 May 2022 23:00:45 -0700 (PDT)
X-Received: by 2002:a4a:b0cc:0:b0:35e:a2b4:bcf3 with SMTP id
l12-20020a4ab0cc000000b0035ea2b4bcf3mr8086802oon.5.1653285645073; Sun, 22 May
2022 23:00:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sun, 22 May 2022 23:00:44 -0700 (PDT)
In-Reply-To: <t6eo7p$qsv$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.233.31; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.233.31
References: <t6emf1$bok$1@gioia.aioe.org> <a68b6e2d-53f1-4d8d-8673-8175730fc305n@googlegroups.com>
<t6eo7p$qsv$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8c415927-e572-44ca-a4ae-87f21f84853bn@googlegroups.com>
Subject: Re: command pipes: puts vs. return
From: martin.heinrich@frequentis.com (heinrichmartin)
Injection-Date: Mon, 23 May 2022 06:00:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: heinrichmartin - Mon, 23 May 2022 06:00 UTC

On Monday, May 23, 2022 at 3:32:45 AM UTC+2, saito wrote:
> On 5/22/22 9:24 PM, mango wrote:
> >
> > I'm not sure what you expectation is here. The original script opens a pipeline to read the standard output of a process as if it were a file. When the original script writes to the standard output (using puts), then indeed the output is seen. When you change the script to omit generating standard output, then you seen nothing. That's sorta what I would expect. Not clear to me what your expectations were.
> >
> >
> Hello,
>
> I was interested in capturing the return value, but using the spawning
> mechanism. But I see what you mean. Thank you.

You've just discovered one difference between interactive and non-interactive tclsh: return values are printed (one per script) in interactive mode only.

Notes:
* This also means that string values are generated for all such return values (follow-up "shimmering").
* Another notable difference is the behavior of the unknown command (follow-up "tcl_interactive").

Re: command pipes: puts vs. return

<t6f868$scl$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: command pipes: puts vs. return
Date: Mon, 23 May 2022 08:04:55 +0200
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <t6f868$scl$1@dont-email.me>
References: <t6emf1$bok$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 23 May 2022 06:04:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="da720c510145c3f3ad94a604b51d75d6";
logging-data="29077"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oRoOsPrY9R9iDjMehaDhv98g4OPKmKz8="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0)
Gecko/20100101 Thunderbird/91.9.0
Cancel-Lock: sha1:rMTGdH7AICSkJF7tm0iMBUrrx1k=
In-Reply-To: <t6emf1$bok$1@gioia.aioe.org>
 by: Christian Gollwitzer - Mon, 23 May 2022 06:04 UTC

Am 23.05.22 um 03:02 schrieb saitology9@gmail.com:
> Hello,
>
> I have a question on the internal processing of command pipes in Tcl.
> When you open a command pipe via [open "|..."' r+] and run a tcl script,

What's your reason to run another Tcl script by this kind of "forking"?
Why do you not simply "source otherscript.tcl" to run it?

I can think of the following reasons:

- If it is to achieve true concurrency, then checkout the package Thread.

- If you just need isolation between both scripts, i.e. not to confuse
variable names, use namespaces or an object system like TclOO or snit.

- If it is for partially untrusted user scripts, use slave interpreters.

Christian


devel / comp.lang.tcl / Re: command pipes: puts vs. return

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor