Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command line args to tcl/tk script

Status
Not open for further replies.

jlynch1

Technical User
Dec 20, 2001
100
IE
I want to be able to run my tcl/tk application on the command line without it displaying the default window .

This window shows when wish is used to run the tcl/tk script even though there are no tk widgets, windows etc. ie no tk code at all.

I am giving the user 2 options
1.) to run it from the command line (showing now windows at all)
2.) to run it with gui (using tk widgets etc)

i am using a variable to keep track of the mode the user is in.

a way around this would be to use tclsh to execute the script using the command line option and wish to execute it for the gui when no command line args are given.

how would i go about solving this
 
#!/usr/bin/tclsh
if {[llength $argv] < 1} {
set mode ?
cli oriented approach here..
}
set mode ?
exec wish $0 $argv
 
Code:
# load Tk if no argument
if {$argc == 0} { load {} Tk; #Tk is now loaded }
You can find information about argc, argv and argv0 in the tclsh page of the Tcl Manual.

And for load at the load page.

HTH

ulis
 
I get the following error when i try to run the command : exec wish $0 $argv

can't read &quot;0&quot;: no such variable
while executing
&quot;exec wish $0 $argv &quot;

What is contained in the variable $0 ?
 
Nevermind: that would be the base script name if you were
running from a non-tclsh shell script.
I realized the mistake looking at it just now.

Try something like this:
#!/usr/bin/tclsh

if {[llength $argv] < 1} {
set mode ?
cli stuff
}
set mode ?
exec wish [file join [pwd ][info script]] $argv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top