Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need to distinguish between if tcl or wish is running!!

70 views
Skip to first unread message

Deepanshu

unread,
Apr 24, 2008, 5:23:14 AM4/24/08
to
Hello,

I have a tcl/tk based application where code is invoked using .bat
files. say there is a command abc.bat which can invoke wish abc.tcl
and there is another command abc_1.bat which invokes tclsh abc.tcl.
Now in abc.tcl I want to handle some errors and display them to user
appropriately like when in Tk mode I wish to use messagebox and when
in "tclsh" mode" its ok to use puts.

Is there any way of knowing it runtime that whether wish or tclsh was
used to invoke this application??

Thanks,
Deepanshu

Arjen Markus

unread,
Apr 24, 2008, 5:45:01 AM4/24/08
to

One way: use [package present Tk]

You either get the version number or a string that it
is not available.

Regards,

Arjen

schlenk

unread,
Apr 24, 2008, 5:45:35 AM4/24/08
to

Sure. There is more than one way to do it. But basically you don't
care about tclsh or wish, you care about Tk being present...

So the sane way is to check for Tk...

(bin) 50 % if {[catch {package present Tk}]} {
puts "No Tk"
} else {
puts "Have Tk"
}
No Tk
(bin) 51 % package require Tk
8.4
(bin) 52 % if {[catch {package present Tk}]} {
puts "No Tk"
} else {
puts "Have Tk"
}
Have Tk

Michael


sleb...@gmail.com

unread,
Apr 24, 2008, 6:02:45 AM4/24/08
to

There are several ways to do this depending on exactly what you mean.
If you REALLY need to find out if you're in tclsh or wish then you can
check [info nameofexecutable]:

set app [info nameofexecutable]
if {[regexp {wish} $app]} {
pack [label .l -text "This is running in wish."]
} elseif {[regexp {tclsh} $app]} {
puts "This is running in tclsh."
} else {
puts "Whoa... we're in some weird custom app!"
}

On the other hand, usually you only need to know if this is a GUI
environment or a command line environment. In which case I usually
find it more robust to check if Tk is loaded:

if {[info commands winfo] == ""} {
puts "We don't have GUI, this is probably tclsh."
} else {
pack [label .l -text "We have GUI capabilities."
}

ZB

unread,
Apr 25, 2008, 7:18:57 PM4/25/08
to
Dnia 24.04.2008 Arjen Markus <arjen....@wldelft.nl> napisał/a:

> One way: use [package present Tk]
> You either get the version number or a string that it
> is not available.

In my opinion: "...or a remains unset" (set a [package present Tk]).
--
ZB

0 new messages