Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/Changing+stdout%2C+redefining+puts+and+avoiding+console+show?V=5
QUERY_STRINGV=5
CONTENT_TYPE
DOCUMENT_URI/revision/Changing+stdout,+redefining+puts+and+avoiding+console+show
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.130.177
REMOTE_PORT51020
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.144.28.65
HTTP_CF_RAY886d3503bea28140-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_REFERERhttps://wiki.tcl.tk/revision/Changing+stdout%2C+redefining+puts+and+avoiding+console+show?V=5
HTTP_CF_CONNECTING_IP3.144.28.65
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {Changing stdout, redefining puts and avoiding console show} {[Zipguy]  2014-01-31 - You can find out my email address by clicking on [Zipguy].   

This started in Tkchat when I had a problem on Windows, but it does highlight some useful things, namely,  nice short illustrations of transchan and refchan.  I'd never even thought about channels, nevermind transchan and refchan.  What I said, in chat, was something like 'I'm thinking of writing a Bwidget to replace the puts function in a namespace/package combo', and what I got back was an answer that puzzled me. It was 'Maybe you can also close stdout and then open a reflected channel to catch everything that's being puts'ed to stdout'. So instead of asking a question, I thanked everyone in chat. Then I got two teriffic answers, totally different, by two different people in chat a few minutes later.  

Here's the first one which was called 'transforming stdout'.  It's an example of (misusing) a [transchan]:  We [chan push] a transformer onto stdout that intercepts writes and simply neglects to pass them on to the original channel.
======
# see http://wiki.tcl.tk/21282 (chan push)
namespace eval totk {
  proc initialize args {info procs}
  proc finalize args {}
  proc clear args {}
  proc flush {handle} {
    flush $handle
  }
  proc write {handle data} {
    .t insert end $data
  }
  namespace export *
  namespace ensemble create
}
 package require Tk
 pack [text .t]
 
 chan push stdout totk 
======

and the second one which was called 'replacing stdout'.  This is almost the same thing using a [refchan].  It relies on [file descriptors] being reused:  if you close stdout and immediately create another channel, it will inherit the same fd and nobody is the wiser.  Reportedly this works cross platform.
======
    package require Tk
    pack [text .t]
     
    namespace eval refchan {
      namespace ensemble create -map {
        initialize init
        finalize close
        watch watch
        write write
      }
    }
     
    proc refchan::init {id mode} {
      return {initialize finalize watch write}
    }
     
    proc refchan::finalize {id} {
    }
     
    proc refchan::watch {id spec} {
    }
     
    proc refchan::write {id data} {
      .t insert end $data
      return [string length $data]
    }
     
    close stdout
    set fd [chan create write refchan]
    fconfigure $fd -buffering line
     
    puts "Hello, World!"
    parray tcl_platform
======

[aspect] interjects much later:  looking again at [tcllib], there are some standard modules that can make this even simpler:
======
package require tcl::chan::textwindow
package require tcl::transform::observe
::tcl::transform::observe stdout [::tcl::chan::textwindow .t]
====
Refchans and transformers are easy, as evidenced by the implementations above, but knowing about [https://core.tcl.tk/tcllib/doc/trunk/embedded/www/toc.html%|%standard components%|%] can save some bug-hunting :-).

[Zipguy] continues:  I tried the first one. Lo and behold, I used it in my program [http://wiki.tcl.tk/29317%|%ezsdx - a small frontend for sdx%|%] and it worked great!  Needless to say, I was extremely happy with that.  This is what ezsdx looked like, once I first got it working:

[http://www.geocities.ws/thezipguy/tcl/ezsdx/EasySDX_01a.png]

Notice, above, that all my puts statements are not it a seperate window, but in a text item, in a frame in my main application. Way to cool!  And even better, SDX's puts are there too! So I did a lot of work on ezsdx, and have a much better version of it, on Windows (7).  It gets rid of the problem of havng to switch back and forth, imbetween the app's window and the console window, to see if your program worked, or for one that you haven't written, like SDX, which does uses puts completely.

Even better you can use colors in text widgets, like this [http://www.geocities.ws/thezipguy/tcl/ezsdx/_thmb/image.html] or:

[http://www.geocities.ws/thezipguy/tcl/ezsdx/_thmb/EasySDX_01.png]

The second solution looks very interesting too! Haven't tried it yet.

Comments are welcome.

[APN] Interesting. However, the second solution does not seem to work, at least on Windows. stdout gets closed and the new channel is created. But the new channel does not get "attached" to stdout. `puts $fd foo` works but `puts foo` errors out with a stdout channel not found message. `chan names` also does not show stdout. Possibly this issue is related to the Windows wish console which does not really seem to be a full fledged channel, or perhaps the stdout replacement does not work with reflected channels.

[Zipguy] 2014/05/18 - I'm real happy with the first solution.  I want to keep trying it, and looking for improvements, and then make it into a proper package and namespace, that I can install into each of the programs I've written. That should make them a lot more portable, and get rid of the problems on Window Vista, or up.  Here's what I have so far, the console window is collapsable:

[http://www.geocities.ws/thezipguy/tcl/ezsdx/EasySDX_01b.png]



<<categories>> Tk | Arts and crafts of Tcl-Tk programming | Windows | SDX | Tclkit} regexp2} CALL {my render {Changing stdout, redefining puts and avoiding console show} {[Zipguy]  2014-01-31 - You can find out my email address by clicking on [Zipguy].   

This started in Tkchat when I had a problem on Windows, but it does highlight some useful things, namely,  nice short illustrations of transchan and refchan.  I'd never even thought about channels, nevermind transchan and refchan.  What I said, in chat, was something like 'I'm thinking of writing a Bwidget to replace the puts function in a namespace/package combo', and what I got back was an answer that puzzled me. It was 'Maybe you can also close stdout and then open a reflected channel to catch everything that's being puts'ed to stdout'. So instead of asking a question, I thanked everyone in chat. Then I got two teriffic answers, totally different, by two different people in chat a few minutes later.  

Here's the first one which was called 'transforming stdout'.  It's an example of (misusing) a [transchan]:  We [chan push] a transformer onto stdout that intercepts writes and simply neglects to pass them on to the original channel.
======
# see http://wiki.tcl.tk/21282 (chan push)
namespace eval totk {
  proc initialize args {info procs}
  proc finalize args {}
  proc clear args {}
  proc flush {handle} {
    flush $handle
  }
  proc write {handle data} {
    .t insert end $data
  }
  namespace export *
  namespace ensemble create
}
 package require Tk
 pack [text .t]
 
 chan push stdout totk 
======

and the second one which was called 'replacing stdout'.  This is almost the same thing using a [refchan].  It relies on [file descriptors] being reused:  if you close stdout and immediately create another channel, it will inherit the same fd and nobody is the wiser.  Reportedly this works cross platform.
======
    package require Tk
    pack [text .t]
     
    namespace eval refchan {
      namespace ensemble create -map {
        initialize init
        finalize close
        watch watch
        write write
      }
    }
     
    proc refchan::init {id mode} {
      return {initialize finalize watch write}
    }
     
    proc refchan::finalize {id} {
    }
     
    proc refchan::watch {id spec} {
    }
     
    proc refchan::write {id data} {
      .t insert end $data
      return [string length $data]
    }
     
    close stdout
    set fd [chan create write refchan]
    fconfigure $fd -buffering line
     
    puts "Hello, World!"
    parray tcl_platform
======

[aspect] interjects much later:  looking again at [tcllib], there are some standard modules that can make this even simpler:
======
package require tcl::chan::textwindow
package require tcl::transform::observe
::tcl::transform::observe stdout [::tcl::chan::textwindow .t]
====
Refchans and transformers are easy, as evidenced by the implementations above, but knowing about [https://core.tcl.tk/tcllib/doc/trunk/embedded/www/toc.html%|%standard components%|%] can save some bug-hunting :-).

[Zipguy] continues:  I tried the first one. Lo and behold, I used it in my program [http://wiki.tcl.tk/29317%|%ezsdx - a small frontend for sdx%|%] and it worked great!  Needless to say, I was extremely happy with that.  This is what ezsdx looked like, once I first got it working:

[http://www.geocities.ws/thezipguy/tcl/ezsdx/EasySDX_01a.png]

Notice, above, that all my puts statements are not it a seperate window, but in a text item, in a frame in my main application. Way to cool!  And even better, SDX's puts are there too! So I did a lot of work on ezsdx, and have a much better version of it, on Windows (7).  It gets rid of the problem of havng to switch back and forth, imbetween the app's window and the console window, to see if your program worked, or for one that you haven't written, like SDX, which does uses puts completely.

Even better you can use colors in text widgets, like this [http://www.geocities.ws/thezipguy/tcl/ezsdx/_thmb/image.html] or:

[http://www.geocities.ws/thezipguy/tcl/ezsdx/_thmb/EasySDX_01.png]

The second solution looks very interesting too! Haven't tried it yet.

Comments are welcome.

[APN] Interesting. However, the second solution does not seem to work, at least on Windows. stdout gets closed and the new channel is created. But the new channel does not get "attached" to stdout. `puts $fd foo` works but `puts foo` errors out with a stdout channel not found message. `chan names` also does not show stdout. Possibly this issue is related to the Windows wish console which does not really seem to be a full fledged channel, or perhaps the stdout replacement does not work with reflected channels.

[Zipguy] 2014/05/18 - I'm real happy with the first solution.  I want to keep trying it, and looking for improvements, and then make it into a proper package and namespace, that I can install into each of the programs I've written. That should make them a lot more portable, and get rid of the problems on Window Vista, or up.  Here's what I have so far, the console window is collapsable:

[http://www.geocities.ws/thezipguy/tcl/ezsdx/EasySDX_01b.png]



<<categories>> Tk | Arts and crafts of Tcl-Tk programming | Windows | SDX | Tclkit}} CALL {my revision {Changing stdout, redefining puts and avoiding console show}} CALL {::oo::Obj243238 process revision/Changing+stdout%2C+redefining+puts+and+avoiding+console+show} CALL {::oo::Obj243236 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4