I installed tcl803.exe on my windows XP Operating System and my TCL path is C:\Tcl. Now I am unable to execute the TCL script on windows XP operating system. Please help me. Here I am very new. Please tell me each and every steps. Here is my TCL script. I write in a notepad and save it as a.tcl extension.
set x 50
set y 400
puts stdout "$x+$y=[expr {$x+$y}]"
puts stdout "-The addition of two variables $x and $y is [expr $x+$y]"
Do this at a DOS prompt:
assoc .tcl=TclScript
ftype TclScript=c:\Tcl\tclsh.exe %1 %*
However, it would be much easier for you to install ActiveTcl -- that install process will manage the file associations for you.
Tcl files aren't compiled, they're scripts that require they be handed to a Tcl interpreter to run. You have two primary options on Windows:
Run the tcl interpreter with the script as an argument:
tclsh.exe ddd.tcl
Associate .tcl files with the tclsh (or wish) interpreters. I don't recall how to do this offhand, but it's similar to associate .doc items with Word... When you double click on the .tcl file it calls the executable (Tcl) and gives it the name of the .tcl file you clicked on.
Note: You can "compile" tcl code into an executable (tclkit, starkit), but you probably aren't at a point where you'd be comfortable doing so.
Related
It is possible to call other programs from Tcl using the Tcl exec function. Let’s use this
command to create a Tcl script that will take all of the Tcl code you have written so far and
create a single PDF from it. The filename of the single PDF file should be TCL CODE.pdf.
Recall that the Tcl foreach command makes it very easy to go through a list of items.
You should use the exec command to call the Linux program called enscript to produce
a postscript file for each of the Tcl files. You should then use the Linux program called
ps2pdf to turn each of the postscript files into a PDF. Finally, merge all of the PDFs using
the Linux program called gs (short for ghostscript). Invoke ghostscript using the following
command
Some documentation
Tcl documentation
the exec man page
Tcl tutorial
the wiki entry for exec
I don't program in TCL but I do use them such as tkcvs and tkdiff. I notice that they declare themselves as shell script
#!/bin/sh
#-*-tcl-*-
What's more, running them through tclsh doesn't work either and I get error like this:
Initialization failed
The second line in the header baffles me too because AFAIK, shell only looks at the #! line. How's this working?
Tcl scripts are normally setup to run using slightly more than you have shown. It is typically and most robustly done like the following:
#!/bin/sh
# \
exec tclsh "$0" ${1+"$#"}
They use the shell initially because there was no standard installation location for tcl so the location could not be relied on. Instead, by starting the system shell and using that to start the tclsh executable you could be certain to run the installed tclsh as long as it was present on the PATH. The shell evaluates the script and sees the exec tclsh "$0" which causes it to execute the installed tclsh binary and pass it $0 (the script file name) as the first argument, which re-runs the script using the tcl interpreter.
The second line in my example comments out the third line when the script is evaluated by the tcl interpreter. The backslash causes the second and third lines to be treated as a single comment when read by tclsh so that tcl doesn't try and run the exec again.
In your snipped the # -*-tcl-*- is marker to indicate the mode to be used by emacs when editing the file. See the documentation.
There is not really enough to go on for the error message. It doesn't seem to be from the Tcl interpreter itself. (That is 'git grep' in the tcl sources does not match that string).
How can use Tcl command in windows-7 ? I want to copy one file to other locaiton using a .bat file.
How can use Tcl command in windows-7 ?
Windows (of all versions) has never come with a Tcl interpreter pre-installed, By far the simplest way is to get a copy of ActiveTcl installed.
Once you've got that installed, either run it interactively and just type your Tcl command in at the prompt, or use a text editor (like Notepad) to make a file (conventionally with extension .tcl) that contains the command or commands to execute; you'll probably be able to make the file run by just double-clicking on it.
I want to copy one file to other locaiton using a .bat file.
That's not really got much to do with Tcl. With Tcl, you would use:
file copy {C:\Where\To\Copy\From.txt} {C:\Where\To\Copy.to}
Note, we've put the filenames in {curly braces} here so that we can use backslashes; if we weren't doing that, we'd need to use double-backslashes instead (\\) or forward slashes (/).
The alternative, if you're really wanting to use a .bat file, is to look up what the cmd.exe commands COPY and (less likely) XCOPY do. But that's not a Tcl question.
I am trying to run a very simple tcl script
package require Expect
spawn sftp user#host
the error I get is
The system cannot find the file specified.
while executing
"spawn sftp user#host"
The only reason I see it's that sftp path should be specified somehow. I call this from a batch script and I've also tried changing the directory to sftp location before calling the script but the error is still the same.
By far the most likely cause of the issue here is that the sftp program is not in a directory that is on your PATH. The concept is almost the same across platforms, but with some minor niggles.
Working with the Unix PATH
Check to see if sftp is available in a PATH-known directory by typing:
which sftp
At your shell prompt. It should respond with the location of the sftp program, but if it isn't found then you get no response at all. If it isn't found, you'll need to find it yourself and add its location (strictly, the directory that contains the program) to the PATH. Find the program with something like:
locate sftp
Or (very slow!):
find / -name sftp -print
To append a directory to the PATH, do this in your shell:
PATH=$PATH:/the/dir/to/append
You can add a directory within the Expect script too (as long as it is before the spawn, of course!):
append env(PATH) : /the/dir/to/append
Working with the Windows PATH
On Windows, use Windows Search (Windows+F IIRC) and look for a file called sftp.exe (there's also a command line search tool, but I forget how to use it).
With the Windows PATH, a little more care is required:
append env(PATH) ";" {C:\the\dir\to\append}
# Or this...
append env(PATH) ";" [file nativename C:/the/dir/to/append]
Which is to say, the Windows PATH uses a different separator character (because : is used for separating drive names from directory parts) and the native name of the directory must be used, rather than the somewhat-more-convenient forward-slash variation (the backslashes interact with Tcl's syntax, hence the {braces}). Forward-slashes can be used provided you use file nativename to convert before appending, as in my second version.
Some Tcl Techniques that can Help
You can use the Tcl command auto_execok to find out whether a program is on your PATH or not. For example:
puts [auto_execok sftp]
However, for some commands (notably start on Windows) you get a more complex response; the command really exists as part of the code that supports interactive Tcl usage, describing how to run some external program which can sometimes be a lot more complex than it appears to be at first glance. Still, it approximates to a cross-platform version of which as listed in the beginning of this answer...
Tcl 8.6 provides $tcl_platform(pathSeparator) variable as a way to get the PATH element separator character (a : or ;, depending on platform). Probably doesn't help you though, as 8.6 hasn't yet been distributed as widely as previous versions.
After running into major compatitiblity problems with C#, ASP.NET, MS Access, Linux, and Mono, I've decided to program in a language that is cross-platform, open source, and compatible with embedded databases that are also compatible with many platforms. I narrowed my choice down to TCL.
Before I began a sample application with TCL, I wanted to see how easy it was to create a stand alone application. I purchased a book entitled "Practical Programming in TCL and TK", downloaded TCLkit, and FreeWrap, yet I am having troubles finding a methodological way to convert TCL in TK (Wish) into a standalone application.
Would anyone be able to provide simple steps towards converting a TCL TK script, such as a label with text on it, into an application, or a web resource that has a pretty straight forward explanation?
To build a starpack you need a) a tclkit runtime, b) sdx.kit. You also need a "basekit", the executable that will be wrapped with your tcl code. For this example I'll assume you're creating an application for the same platform you are running on. You can create a basekit by simply copying tclkit (or tclkit.exe on windows) to another name, such as "basekit"
% ls
sdx.kit tclkit
% cp tclkit basekit
% ls
basekit sdx.kit tclkit
Now, create the code that you want to have wrapped into an executable. The convention is to create a directory with the name of your app and the suffix ".vfs" (for 'virtual file system'), then create a file named 'main.tcl' in that directory:
% mkdir myapp.vfs
% cat > myapp.vfs/main.tcl
package require Tk
label .l -text "Hello, world"
pack .l
^D
% ls myapp.vfs
main.tcl
Now to do the wrapping: for this you'll need the sdx.kit file. Assuming it and tclkit (or tclkit.exe) are in your current working directory, you wrap your app like this:
% ./tclkit sdx.kit wrap myapp -runtime basekit
1 updates applied
% ls
basekit myapp myapp.vfs sdx.kit tclkit
The wrap command knows when you give it the argument "myapp" that it should wrap the contents of myapp.vfs, and that it should look for a file named "main.tcl" in that directory to be the program entry point. You can put whatever other files you want in that directory and they will all be wrapped, including platform-specific binary files, image files and anything else you want bundled up.
You now have an executable file, 'myapp', that is the wrapped application.
If you have the tclkits for different architectures you can use them (replacing 'basekit' on the command line with the kit for the target architecture) to cross-compile for other platforms.
For more information see How to create my first Starpack on the Tcl'ers Wiki
kitgen build system may also help you at the beginning.