Re: New to this tcl lark... Why won't the exec do what I want?



On Mon, 22 Oct 2007 05:49:09 -0700, yonorri <yonorri@xxxxxxxxxxxxxx>
wrote:

The following nearly does what I want it to do, except that the exec
part of the button -command only ever packs as the last option in the
servers list, so in this case all four buttons display the correct
server name but only ever run 'DCV3.nxs'


It's actually worse than that....

[snip initialization gunk]

foreach {server} $servers {
button .mF.[string tolower $server] -text $server \
-width 20 -font $font1 -bg #8fb3d9 \
-activebackground #334a73 \

so far so good, although it might be a neat idea to capture the
result of the [button] command for later use in the [pack] so
you don't need to recompute its name

-command {exec /usr/NX/bin/nxclient \
--session /home/mnorris/.nx/config/$server.nxs &}

Ahah! The culprit! The whole [exec] command is in braces, so
$server goes into the exec string LITERALLY, and isn't substituted
until you push the button some time later. By this stage, $server
contains the value from its very last trip around the loop.
In fact you've lucked-out because you're doing this at the top
level of your script, so 'server' is global; if you had
built the GUI in a proc, as you surely will in due course,
then 'server' would have been local to that proc, and
nonexistent at the future time when the [exec] gets to run.

Consider building your [exec] command using the [list]
command instead:

-command [list exec /usr/kruft --session /kruft/$server.nxs &]

Now your $server gets substituted by the [list] command, and
each button gets the appropriate -command value.

hth
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@xxxxxxxxxxxxx
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
.



Relevant Pages

  • Re: exec() gives output??
    ... > I'd like to execute a command on the server ... > particular command takes a long time to execute, ... A successful call to exec() replaces the Perl script with whatever execis ...
    (comp.lang.perl.misc)
  • vbscript WshShell.exec call in ASP
    ... I have upgraded the WSH on the server to version 5.6 and am no ... My code is very simple - I'm just trying to get a simple exec call working ... No matter what command I ...
    (microsoft.public.scripting.vbscript)
  • vbscript WshShell.exec call in ASP
    ... I have upgraded the WSH on the server to version 5.6 and am no ... My code is very simple - I'm just trying to get a simple exec call working ... No matter what command I ...
    (microsoft.public.inetserver.iis.activeserverpages)
  • Re: exec("zip ...) works very infrequently.
    ... I'm running a PHP script on my ISP's server to zip some files. ... you might add a second parameter to the 'exec' function. ... echo print_r; ...
    (comp.lang.php)
  • Re: String manipulation - taking one long csv string and putting into separate record fields
    ... From what I can work out, it looks as if the script is taking ... "%2147746132" from the computer VPN-01 when attempting to activate the ... computer VPN-01 when attempting to activate the server: ... EXEC xp_startmail ...
    (microsoft.public.sqlserver.programming)