invoke tcl GUI and environmental variable 
Author Message
 invoke tcl GUI and environmental variable

Hi,
I have a tcl file that I can successfully ran in a xtclsh file, but
when I tried to call this file in a tclGUI.tcl file that I wrote.  It
says unknown variable, and it's an environmental variable.  The TCLGUI
file I ran by double clicking on the file name.  Does anyone know why
or have ran into similar problem?
Thanks,
Ann


Sat, 01 Sep 2007 07:09:46 GMT  
 invoke tcl GUI and environmental variable

Quote:

> Hi,
> I have a tcl file that I can successfully ran in a xtclsh file, but
> when I tried to call this file in a tclGUI.tcl file that I wrote.  It
> says unknown variable, and it's an environmental variable.  The TCLGUI
> file I ran by double clicking on the file name.  Does anyone know why
> or have ran into similar problem?
> Thanks,
> Ann

What OS?

What version of Tcl/Tk?

What environment variable?

BTW, xtclsh is a non-standard build, so it may be doing something a bit out
of the ordinary.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester               | "The man who fights for his ideals is |

+--------------------------------+---------------------------------------+



Sat, 01 Sep 2007 10:51:20 GMT  
 invoke tcl GUI and environmental variable
Hi an environmental variable in a chipscope file tcljtag.tcl.
...
...
if {[regexp -nocase "windows" $tcl_platform(os)]} {
    set JTAGCOMMDLL  "libJtagcomm10.dll"
    set TCLJTAGDLL   "libTclJtag10.dll"
  } else {
    set JTAGCOMMDLL  "libJtagcomm10.so"
    set TCLJTAGDLL   "libTclJtag10.so"
  }
...
...
$tcl_platform(os) is unknown.  My version of Tcl/tk is 8.4.9.0.

This is the procedure I used to call that file:

proc open_handle {} {
source tcljtag.tcl

Quote:
}

The error I get is: unknown variable.
Thanks,
Ann


Sat, 01 Sep 2007 22:32:44 GMT  
 invoke tcl GUI and environmental variable

Quote:

> Hi an environmental variable in a chipscope file tcljtag.tcl.
> ...
> ...
> if {[regexp -nocase "windows" $tcl_platform(os)]} {
>     set JTAGCOMMDLL  "libJtagcomm10.dll"
>     set TCLJTAGDLL   "libTclJtag10.dll"
>   } else {
>     set JTAGCOMMDLL  "libJtagcomm10.so"
>     set TCLJTAGDLL   "libTclJtag10.so"
>   }
> ...
> ...
> $tcl_platform(os) is unknown.  My version of Tcl/tk is 8.4.9.0.

> This is the procedure I used to call that file:

> proc open_handle {} {
> source tcljtag.tcl
> }

> The error I get is: unknown variable.

tcl_platform is a global variable, and you are neither declaring it as
global or fully qualifying the path to the variable. Either of these
solutions will work:

     proc open_handle {} {
         global tcl_platform
         source tcljtag.tcl
     }

... or:

     if {[regexp -nocase "windows" $::tcl_platform(os)]} {
         ....

BTW: tcl_platform is not an environment variable. Environment variables
are those that come from the global env array.



Sat, 01 Sep 2007 22:50:07 GMT  
 invoke tcl GUI and environmental variable
Hi,

This is a little bit more of that tcljtag.tcl file:
if {[regexp -nocase "windows" $tcl_platform(os)]} {
    set JTAGCOMMDLL  "libJtagcomm10.dll"
    set TCLJTAGDLL   "libTclJtag10.dll"
  } else {
    set JTAGCOMMDLL  "libJtagcomm10.so"
    set TCLJTAGDLL   "libTclJtag10.so"
  }

#############################################################################

proc FindFileInPath {filename} {
  global env
  global tcl_platform
  if {[regexp -nocase "windows" $tcl_platform(os)]} {
    set splitStr ";"
  } else {
    set splitStr ":"
  }
  set paths [split $env(PATH) $splitStr]
  foreach path $paths {
    set retval [glob -nocomplain -directory "$path" "$filename"]
    if {[string length $retval] > 0} {
      return $retval
    }
  }
  return ""

Quote:
}

So tcl_platform is declared in their procedure, so when I call source
on this file, do I have to declare it again????  I tried to do what you
said and declare it in open_handle, then I get an error on env, so  I
declared both tcl_platform and env in open_handle, but the program
crashed.  How do you fix this?  Why is it that when you say exec tclsh
tcljtag.tcl, it works, but when you say "source tcljtag.tcl," you get a
lot of problem????
Thanks,
Ann


Sat, 01 Sep 2007 23:02:42 GMT  
 invoke tcl GUI and environmental variable

Quote:

> So tcl_platform is declared in their procedure, so when I call source
> on this file, do I have to declare it again????  

No.

Quote:
> I tried to do what you
> said and declare it in open_handle, then I get an error on env, so  I
> declared both tcl_platform and env in open_handle, but the program
> crashed.

Define "crashed". Did you get a tcl error, or did the executable core dump?

It sounds like declaring both tcl_platform and env is the right solution
to the original problem, and now you have to find out why it's crashing.

What message do you see when it crashes?

  How do you fix this?  Why is it that when you say exec tclsh

Quote:
> tcljtag.tcl, it works, but when you say "source tcljtag.tcl," you get a
> lot of problem????

Because 'source' and 'tclsh' are two completely, totally different
things. Most likely the problem is because you're doing the source from
a procedure, and when you run the code via tclsh the code executes in
the global namespace.

What *might* work is to rewrite open_handle to look like this:

     proc open_handle {} {
         uplevel #0 [list source tcljtag.tcl]
     }

That will cause the code in tcljtag.tcl to run in the global scope,
more-or-less mimicing what happens if you do "tclsh tcljtag.tcl" from
the command line. That's a rather odd way to go about it, but maybe that
will at least help you get over this hump. If that makes the problem go
away, peharps we can next focus on a better way to organize your code.



Sun, 02 Sep 2007 00:00:09 GMT  
 invoke tcl GUI and environmental variable
Hi, when I said crash, it says "Wish Application has encountered a
prbolem and needs to close.  We are sorry for the inconvenience".  What
I don't understand still is that I can do this in a command line and it
will work
1)  Invoke xtclsh in a shell
2) type source C:/Xilinx/Chipscope_pro_6_3i/tcljtag.tcl

but when I tried the same thing in open_handle:
proc open_handle {} {
         exec xtclsh [source C:/Xilinx/Chipscope_pro_6_3i/tcljtag.tcl]

Quote:
}

It doesn't recognize the env and tcl_platform.  Declaring them cause
the program to crash.
But another thing that I have tried is I put this line in a completely
different file

open_handle.tcl
source $env(XILINX)/ChipScope_Pro_6_3i/tcljtag.tcl

then in my open handle I did
proc open_handle {} {
exec xtclsh open_handle.tcl

Quote:
}

And this works, but this is not how I wanna do it.  Is there a
different between running it in a shell and in a GUI.tcl file or
something?  Why is it that source work on a xtclsh shell but not in a
tcl file?
The way that you just showed me above didn't work, the program crashed.
Thanks,
Ann


Sun, 02 Sep 2007 00:31:52 GMT  
 invoke tcl GUI and environmental variable


Quote:
> Hi, when I said crash, it says "Wish Application has encountered a
> prbolem and needs to close.  We are sorry for the inconvenience".  What
> I don't understand still is that I can do this in a command line and it
> will work
> 1)  Invoke xtclsh in a shell
> 2) type source C:/Xilinx/Chipscope_pro_6_3i/tcljtag.tcl

> but when I tried the same thing in open_handle:
> proc open_handle {} {
>          exec xtclsh [source C:/Xilinx/Chipscope_pro_6_3i/tcljtag.tcl]
> }

[...]
> Thanks,
> Ann

The line:
  exec xtclsh [source C:/Xilinx/Chipscope_pro_6_3i/tcljtag.tcl]
says to the Tcl interpreter:  
  Source (read and execute) the file into THIS interpreter in the
context of this (open_handle) proc .  Build a 3-element list from
"exec", "xtclsh", and the result of the source command (the null
string, I think).  Strip off the first element (exec) and run that
proc with the other elements, xtclsh and a null string as arguments.  

The [exec] command interprets xtclsh as an external command to ask
the operating system to run and the null string as an argument to
pass to xtclsh.  Any output from xtclsh is accumulated and becomes
the result of exec, which becomes the result of your open_handle
proc.  If xtclsh writes anything to stderr or returns a non-zero
exit code (possibly because it was invoked with a single argument,
the null string), exec throws an error.  

In any event, this is no no way equivalent to typing a source
command into an interactive tcl interpreter.  
--



Sun, 02 Sep 2007 08:56:30 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. tcl environmental variable

2. conversion Tcl/Tk (with GUI) to Tcl (without GUI)

3. Environmental variable for vw home on linux

4. Setting DOS environmental variable

5. Environmental Variable

6. Environmental variables in Rexx program (NT)

7. Environmental variables in MASM 6.11d setup

8. Environmental variables in MASM 6.11d setup

9. Environmental variables

10. Environmental Variables in LE COBOL on an IBM mainframe

11. Environmental Variable from MF COBOL

12. Setting environmental variables from f77

 

 
Powered by phpBB® Forum Software