Re: (newbie) storing outputs from all lines of procs into a string
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: (newbie) storing outputs from all lines of procs into a string

From: Bryan Oakley <oakley@bardo.clearlight.com>
Date: Tue Dec 20 2005 - 18:49:31 CET

just80n@gmail.com wrote:
> guys... just some more help :
>
> here is my final proc :
>
> proc DYN_ex {COMMAND} \
> {
> global OUTPUT
> set OUTPUT ""
> rename puts _puts
> proc puts args { append ::OUTPUT $args "\n"; eval _puts $args}
> set retoureval [eval $COMMAND]
> rename puts {}
> rename _puts puts
> append OUTPUT $retoureval
> return $OUTPUT
> }
>
>
> I have also a
> proc choucroute{} {
> puts "abc def"
> puts "ghi jkl"
> return
> }
>
> when I launch this proc using DYN_ex, I get
>
> % DYN_ex choucroute
> qdsfsd 33
> qdsfsd 4444 4
> {qdsfsd 33}
> {qdsfsd 4444 4}
> choucroute
>
>
> the last 3 lines are the "return from DYN_ex";
>
> First, how to get rid of the "{" "}" ....

Try this:

    append output [join $retoureval " "]

>
> Then, if I send a wrong command: DYN_ex bidule for instance (assuming
> bidule does not exists)
> DYN_ex will return in the middle of its execution
> (at line : set retoureval [eval $COMMAND] to be precise)
> and won't complete the last critical steps:
> rename puts {}
> rename _puts puts
>
> ... how can I handle that?
>

instead of:

    set retoureval [eval $COMMAND]

try this:

    catch $command retoureval

catch is like eval in that it runs a bit of code. Unlike eval, it
catches errors. You can even test for errors as catch returns a non-zero
value in case of an error:

    if {[catch $command retoureval]} {
       append output "Error evaluating '$command': $retoureval"
    }
Received on Fri Dec 23 19:02:34 2005