Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2006-09-13
08:08 • Ticket [1556342fff] set stdin/stdout/stderr with interp transfer/share statu... artifact: 0e9d185e88 user: nobody
2006-09-11
22:53 • Ticket [1556342fff]: 4 changes artifact: 0626a959e6 user: dgp
13:06 • New ticket [1556342fff]. artifact: fd1e5b5c15 user: nobody

set stdin/stdout/stderr with interp transfer/share

Open1556342fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 20 years ago
Descriptionplain2006-09-11 13:06:36
The methods for setting stdin/stdout/stderr are pretty clunky, 
especially from the script level.  It also doesn't seem to work well when 
trying to set a slave interpreter to have stdin/stdout/stderr be 
something different from the master interpreter.

I suggest an optional additional argument on the transfer/share 
subcommands of the interp command:

interp share srcPath channelId destPath ?channelName? 

e.g.

interp transfer {} [open /dev/tty] $interp stdin

or something like that (where channelName could be restricted to only 
be stdin/stdout/sterr, or could be more general to have other "named" 
channels, which would be interesting in and of itself).

Alternatively, I was thinking maybe this should go on the new chan 
command, perhaps something like:

chan set channelName channelId

e.g.

chan set stdin [open /dev/tty]

If that was available, then it could still be done a bit messily without a 
change to interp:

set handle [open /dev/tty]
interp transfer {} $handle $interp
interp eval $interp chan set stdin $handle

The above should hide the file5 (or whatever) channel ID from the list 
of open channels ([file channels] or [chan names]), just as a fresh 
interpreter would when it initialized stdin/stdout/stderr, which is why 
it might be better to have this on the interp command in the first place.

Perhaps both are appropriate, however.

Note that having this would make most or even all of the tkConsole.c 
code unnecessary, as it could all be done with scripts and the new chan 
command's ability to create a procedural channel.

[email protected]
dgpplain2006-09-11 22:53:25
Logged In: YES 
user_id=80530


Just a quick comment to note
that currently Tcl forces
one shared set of std
channels for all interps in
the same thread.  From a
quick read, it seems what's
sought here is a pretty fundamental
re-thinking of that.  It's not
just a matter of providing
some better commands to more
easily access something we can
do now.  It's a request to make
possible something that's not
possible at all currently.

We've only fairly recently
moved from the "entire app
uses the same std channels"
model to "each thread has
a set of std channels" model.

All of this may be obvious
to the anonymous submitter,
but worth noting here for
others reading.
nobodyplain2006-09-13 08:08:32
Logged In: NO 

Actually, I didn't realize quite how bad it was, I should have figured it out, 
though, since the Get/SetStdChannel routines don't take an interpreter 
argument.  I didn't realize it was as bad as having the GetChannelNames and 
GetChannel calls actually hardcoding in the stdin/out/err names, though.

What's needed is to get away from the idea that the "channel name" is fixed 
and immutable and is what should be registered in the channel name hash 
table in each interpreter.  Leaving the current RegisterChannel to pick the 
name out of the channel, and adding a new one to allow registering it under a 
supplied name, as well as requiring a name to unregister it, would seem to 
me to be mostly all that would be needed.  Fix the few places that unregister 
a channel (i.e. close) to supply the channel name instead of having it be 
implicit, and you're done.

Get/SetStdChannel would still supply the defaults for a new interpreter, but 
wouldn't have the weird effects it now has if there is a slave interpreter 
already initialized when you change the standard channels and it doesn't have 
the "real" new channel already registered.

[email protected]
Log in (anonymous is fine) to add a comment.