Tcl Source Code

View Ticket
Login
Ticket UUID: 792990
Title: Redirect file output into variables
Type: RFE Created on: 2003-08-22 07:47:05
Submitter: elfring Assigned to: andreas_kupries
Subsystem: 37. File System Severity:
Priority: 5 Medium Last modified: 2007-11-15 20:15:02
Status: Closed Closed by: andreas_kupries
Resolution: Duplicate Closed on: 2007-11-14 22:55:30
Version: None
Description:
The PHP programming language provides output control 
functions 
(http://de.php.net/manual/en/ref.outcontrol.php, e. 
g. "ob_get_contents"). I would like to use similar 
functionality with TCL.

1. http://tcl.tk/man/tcl8.4/TclCmd/open.htm
I suggest to add a parameter that specifies a variable 
name.
open $fileName $access $permissions $varName
   or
open -var $Name $fileName $access $permissions

2. http://tcl.tk/man/tcl8.4/TclCmd/fconfigure.htm
I suggest to add an interceptor and options to switch 
the output into variables on and off on the fly.
fconfigure -setvar $Name $channelId
fconfigure -stopvar $Name $channelId
fconfigure -getcontents Buffer $channelId
User Comments:
vincentdarley added on 2003-08-22 16:13:21:
Logged In: YES 
user_id=32170

It's not clear from what you write what the behaviour is
that you are seeking for these 4 new commands.  How about
looking at the man pages and adding to this feature request
a few sentences on each option describing what it actually
does and how it is used, perhaps with an example?

elfring added on 2003-08-22 20:36:30:
Logged In: YES 
user_id=572001

1. Open  a new file with the option that all data is written to 
or read from a TCL variable
Example:
if {![catch {open -var Debug stdout w} File]} \
 {
  # Some code to check in a "special" execution environment

  # Do something...
   puts "Surprise"

  # Work is done.
  close $File

  LogResult $Debug
 }


2. Catch a part of file processing
Example:
fconfigure -setvar Debug stdout

# Do something...
puts "Surprise"

fconfigure -stopvar Debug stdout
LogResult $Debug

# Display message to the normal target
puts "finished"

if [file isbuffering stdout] \
 {
  fconfigure -getcontents Buffer stdout
  LogResult $Buffer
 }


Is this little explanation useful?

dgp added on 2003-08-22 20:49:24:
Logged In: YES 
user_id=80530


so you are looking for a new channel
type that is backed by a variable?

Or are you looking for a new filesystem
type where the "files" are really variables?

Either one should be possible in an
extension given Tcl's current public API,
right?  Are you aware of missing interfaces?

The latter one might even be possible
entriely at the scritp level, making use
of the tclvfs package.

elfring added on 2003-08-22 21:13:16:
Logged In: YES 
user_id=572001

Can the requested functions be implemented by two 
techniques?
I've got no preferences. I would like both.

elfring added on 2003-08-23 22:53:33:
Logged In: YES 
user_id=572001

Has anybody tried to create a file system interface for variables before?

vincentdarley added on 2003-09-19 00:41:15:
Logged In: YES 
user_id=32170

I suggest this be discussed on comp.lang.tcl, and then, if
some sort of consensus/design is reached, someone can write
a TIP.  It's all a bit vague and sourceforge isn't really
very convenient for making vague discussions more concrete.

elfring added on 2003-09-19 15:17:56:
Logged In: YES 
user_id=572001

1. How do you think about to create a companion topic 
for "http://mini.net/tcl/memchan" like it was done 
with "http://wiki.tcl.tk/source" for an other request?

2. What kind of convenience are you missing from 
SourceForge?

vincentdarley added on 2003-09-19 15:23:19:
Logged In: YES 
user_id=32170

This bug report/feature request is quite invisible to the
Tcl community, unless someone is actively seeking it out.  A
discussion on the Wiki or comp.lang.tcl is much more visible
and likely to solicit more opinions and lead to a better
solution. After all, I'm the only one who has responded to
this at all. If you believe the idea is a good one, then
surely many people would be interested...

elfring added on 2003-09-19 15:26:37:
Logged In: YES 
user_id=572001

What is better: Wiki or newsgroup or both?

elfring added on 2003-09-21 23:52:50:
Logged In: YES 
user_id=572001

I started the discussion 
"http://groups.google.de/groups?group=comp.lang.tcl&selm=40ed1d8f.0309190825.12f4fac6%40posting.google.com".

elfring added on 2004-07-27 18:45:12:
Logged In: YES 
user_id=572001

Is there anything in common 
with "http://dedasys.com/freesoftware/files/CacheOut.tgz"?

andreas_kupries added on 2007-11-15 05:55:30:
Logged In: YES 
user_id=75003
Originator: NO

This is IMHO subsumed by the TIP #219 (http://tip.tcl.tk/219.html), "Tcl Channel Reflection API". This allows users to write a channel driver in Tcl which stores the written data to a variable, and/or reads from it.
Considered to be now a duplicate of http://sourceforge.net/tracker/index.php?func=detail&aid=1025294&group_id=10894&atid=310894

elfring added on 2007-11-15 20:15:02:
Logged In: YES 
user_id=572001
Originator: YES

Is a channel driver available for the suggested redirection already?
http://wiki.tcl.tk/2701