home
NEWS       BLOGS       FORUMS       NEWSLETTERS       RESEARCH       EVENTS       DIGITAL LIBRARY       CAREERS  
Network Computing Network Computing Powered by InformationWeek Business Technology Network

IMMERSE YOURSELF:

SOA

  |

Data Center

  |

802.11n

  |

Data Privacy

  |
APO  |

Virtualization

  |

NAC

  |

Security

  |

Network Mgmt

  |

Enterprise Apps

  |

Storage & Servers




An Introduction to Tcl and Tk: Listings

Listing 1: The syntax of Tcl commands is quite simple.

A. Command names begin lines, and arguments possibly grouped by quotes or braces follow:

1 set name {Brent Welch}
2 puts stdout "My name is $name"

B. Command substitution occurs inside of square brackets:

1 set d [exec date]
2 puts stderr "Error occurred at $d"

Listing 2: Using Tcl/Tk, it is easy to build a graphical user interface to the ping command.

A. The first version runs ping once and displays the result:

1 #!/usr/local/bin/wish -f
2 # Ping example #1
3 frame .buttons -borderwidth 10
4 pack .buttons -side top -fill x
5
6 button .buttons.quit -text Quit -command exit
7 button .buttons.ping -text Ping -command Ping
8 pack .buttons.quit .buttons.ping -side right
9
10 frame .f ; pack .f -side top
11 label .f.l -text Host:
12 entry .f.host -width 20 -relief sunken
13 pack .f.l .f.host -side left
14
15 text .log -width 60 -height 10 -bd 2 -relief raised
16 pack .log -side top
17
18 proc Ping {} {
20 set hostname [.f.host get]
21 catch {exec ping $hostname} result
22 .log insert end $result
23 .log insert end \n
24 }

B. The helper script continuously sends ping's output to the front end for display:

1 #!/usr/local/bin/wish -f
2 # Install this as "pinghelper"
3 wm withdraw .
4 set hostname [lindex $argv 0]
5 set otherInterp [lindex $argv 1]
6 set in [open "|ping -s $hostname" r]
7 while {[gets $in line] >= 0} {
8 send $otherInterp [list Insert $line]
9 }
10 exit

C. The lines in Listing 2A to change to integrate the pinghelper:

18 proc Ping {} {
19 global pid
20 set hostname [.f.host get]
21 set pid [exec pinghelper $hostname [winfo name .] &]
22 .buttons.ping configure -text Stop -command Stop
23 }
24 proc Insert { text } {
25 .log insert end $text
26 .log insert end \n
27 .log yview -pickplace end
28 }
29 proc Stop {} {
30 global pid
31 catch {exec kill $pid} result
32 .log insert end $result\n
33 .buttons.ping configure -text Ping -command Ping
34 }
Print This Page


e-mail Send as e-mail





Ready to take that job and shove it?

Function:

Keyword(s):

State:
SPONSOR
RECENT JOB POSTINGS
CAREER NEWS
Go beyond Google and get vertical. These specialized search sites will help you find the business information you need -- fast.

Ari Balogh was named to the post of chief technology officer as the companys for a "realignment" of employees.










InformationWeek U.S. IT Salary Survey 2008
Salaries for business technology professionals are falling. Here's what you need to know in order to make good hiring decisions and personal career choices. Download Today
 
ROLLING RIGHT ALONG
Follow key Network Computing Reviews from conception to completion. This Week: Holistic APM.



Network Computing Reports Emerging Enterprise Podcast Series: Secrets to Success








TechSearch


Microsite of the Week


Powerful Information at Your Fingertips



InformationWeek Business Technology Network
InformationWeekInformationWeek 500InformationWeek 500 ConferenceInformationWeek AnalyticsInformationWeek CIO
InformationWeek EventsInformationWeek ReportsInformationWeek MagazinebMightyByte and SwitchDark Reading
Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingNo JitterPlug Into The Cloud
space
Techweb Events Network
InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0 ConferenceMobile Business ExpoSoftware ConferenceCSI - Computer Security Institute
Black HatGTECEnergy CampMashup CampStartup Camp
space
Light Reading Communications Network
Light ReadingLight Reading EuropeUnstrungLight Reading's Cable Digital NewsConstantinopleInternet EvolutionPyramid Research
Heavy ReadingLight Reading Live!Light Reading InsiderEthernet ExpoOptical ExpoTeleco TVTower Technology Summit
space
Financial Technology Network
Advanced TradingBank Systems & TechnologyInsurance & TechnologyWall Street & TechnologyAccelerating Wall StreetBank Systems & Technology Executive SummitBuyside Trading SummitInsurance & Technology Executive Summit
space
Microsoft Technology Network
MSDN MagazineTechNetThe Architecture Journal
space


App Infrastructure   |   Messaging & Collaboration   |   Network & Systems Mgmt   |   Network Infrastructure   |   Security  |   Storage & Servers   |   Wireless   |   Enterprise Apps
About Us  |  Contact Us  |  Site Map  |  Technology Marketing Solutions  |  Advertising Contacts  |   Briefing Centers
Copyright © 2008  United Business Media LLC  |  Privacy Statement  |  Terms of Service  |  Your California Privacy Rights