| 1.3 Direct Execution |
|
|
By With direct execution, there is no command window. Standard input and output will be through the window where the script is executed, if any. Under Windows 95, Tcl will provide a new DOS window for this purpose, if necessary. From the first, Unix has had an elegant mechanism for executing scripts directly. The mechanism requires two preparatory actions:
When you have taken these two preliminary steps for a file script you can execute script with a normal Unix command line, for example, script ARG1 ARG2 ... ARGnwhere ARG1, ARG2, ... ARGn represent arguments passed to the script. Windows 95Scripts can be executed directly in the way Windows 95 expects programs to execute by clicking on them. To arrange for this you need to give your script files a distinctive extension, such as tcl or tk, and to tell Windows about your extension. To tell Windows about your extension, do the following:
If the file type already exists, you can look for it with the scrollbar window that you see after clicking "File Types." Then click on "Edit" and change the windows I have described above as necessary. When Tcl or Tk is executed this way, it is called "direct execution." Tcl
brings up a DOS window that is used for standard input and output this is
not a command window. Tk brings up a root window but not a command window.
With either Tcl or Tk, commands are taken from the script file you double
click on. If that script begins with the first line shown above for
Unix usage, it is OK. Tcl/Tk sees any line beginning with a # as
a comment and ignores it.
If you execute Tcl as just described, you may find the DOS window disappears much too soon. This problem can be fixed with an extra input statement at the end of your scripts if your script catches all possible errors. Another fix is to execute your scripts from a batch file, tcl.bat, whose contents are something like: echo off c:\progra~1\tcl\bin\tclsh80.exe %1 %2 %3 %4 %5 %6 %7 %8 %9 The advantage of the batch file is that it creates the DOS Window from which your script is executed you will have good control over how long that window lasts. A disadvantage is that your scripts are limited to accepting eight or fewer arguments. That probably will not fret you. If you drag tcl.bat from the Explorer to your desktop, Windows will create a shortcut to tcl.bat. After the shortcut is created, right click on the shortcut symbol, then on "Properties," and finally on the "Program" tab. Edit the "Cmd Line" field by adding a space and then a question mark to the end of the line. Enter the directory where you keep your Tcl scripts into the "Working" field. At the bottom of the dialog box, make sure there is no check mark in the "Close on exit" square. Exit the Properties window. Now when you click on the shortcut you will get a window into which you can enter a command line for executing a Tcl script. This window pops up because you used a question mark as an argument in the "Cmd Line" field. Remark
|
Author's Home Page |
|
Order from Amazon. |