How to read input from console in TCL

You might know, we can use puts to write to console like this:
puts "Hello world !"

In this post we will see how to read keyboard input from console using TCL script. Some time we need to take input from user to proceed further, for example adding two numbers. Here is syntax to read :

gets channel_ID variable_Name

Here, channel_ID is id of channel . It specify from where we have to read. To read from console we need to use stdin (standard input) as channel ID.

variable_Name is name of variable where we have to store that text.

Let us check one sample example.

puts "what is your favourite colour ?"
gets stdin name_of_colour
puts "Colour is $name_of_colour"

Output :

C:\Tcl\bin>tclsh inputDemo.tcl
what is your favourite colour ?
Colour is red

Here is another example to add two numbers entered by user :

puts "Enter first number for addition:"
gets stdin first_number

puts "Enter second number for addition:"
gets stdin second_number

set answer [expr $first_number + $second_number]

puts "Addition of $first_number and $second_number is : $answer"


Output will be :

C:\Tcl\bin>tclsh addition.tcl

Enter first number for addition:
Enter second number for addition:
Addition of 33 and 11 is : 44

Data Types in TCL

TCL stores value as Object and every object having String representation and It may have secondary representation if needed.

Let me explain when this secondary represenation is used. For example you assign value to variable like this :

set a 5

TCl will create variable ‘a’ and assign 5 as string value . Now if you use variable ‘a’ where value of ‘a’ will be require as integer (for example arithmetic operations) then TCL will translate the string 5 into integer value. Value of 5 will remain integer until it is required as a string. Check following script and its comments for more detail.

set a 5             ; # a as string

set a [expr $a+4]   ; # a as integer

puts $a             ; # a as string 

See how can we use float value with TCL script .

set a 4.2

set a [expr $a+0.2]

puts $a ;# will print 4.4


List is basically string separated with whitespace . Curly braces or double quotes can be used to represent List.  

set listOfDay {monday tuesday wednesday}

puts $listOfDay ; # output => monday tuesday wednesday

set listOfOdd { 3 5 7 }

puts $listOfOdd ; # outout => 3 5 7


Associative Array

Associative arrays are like Key Value pair. Key can be string value .

set name(IN) "India"
set name(UK) "United Kingdom"

puts "Countries : $name(IN) $name(UK)"

# Output=> Countries : India United Kingdom

How to Develop a Notepad++ Plugin

Notepad++ is best text/source code editor for Windows OS . Lots of good features have been added in Notepad++ . If you want any new feature you can create plugin and use it directly from Notepad++ .
It is possible to create Notepad++ plugin using VC++, C# .Net , Ada . In this tutorial we will see how to create Notepad++ plugin using C# .Net .
1. Download C# .Net Notepad++ Plugin :

To develop plugin in C# .Net you can download Visual Studio C# .net template from this link :
or this direct link for download:

2. Configure Plugin in Visual Studio :
After downloading this package just extract it and copy (unextracted) folder into
C:\Users\YOUR_USER_NAME\Documents\VisualStudio2010\Templates\ProjectTemplates\Visual C#
Restart Visual Studio !
3. Create Plugin In Visual Studio:
To create plugin open Visual Studio, Go to File -> New -> Project and select Notepad++ Plugin. See Screenshot :

notepad++ plugin in visual studio

Give name to project and click OK . You will see already added methods in Main.cs file . By default this template comes with 2 menus MyMenuCommand and MyDockableDialog in CommandMenuInit() method .We will add our own new menu . To add new menu go to method CommandMenuInit() and paste following line before idMyDlg = 1;

PluginBase.SetCommand(2, “Hello Notepad”, helloNotepadPP);

We have defined new menu but for this menu we will need function pointer. Function pointer is name of method which will be invoked after executing our newly created command “Hello NotepadPP”
Copy and paste following function as function pointer in Main.cs file:

internal static void helloNotepadPP()
            MessageBox.Show(“Hello Notepad++ this is my first plugin !!!”);

Save Project. Finally code will look like this :

Notepad++-plugin code

4.Build Visual Studio Plugin Project:

Go to Menu Build -> Build Solutions. Build will create .DLL file in binDebug or binRelease folder depend on your Solution configurations. Copy this .DLL file and paste into Notepad++ Plugin folder . For me it is found in this path : C:Program Files (x86)Notepad++plugins . Restart Notepad++ .

5. Run your First Plugin :

After restart you will see New Plugin is added in Plugins menu . See screenshot:

Notepad++ run pluginThis is just simple plugin for demonstration ! Check this tutorials video :

How to debug a TCL script using eclipse

Eclipse is consider as good IDE for development as well as debugging . In last article we have seen how to configure eclipse to run TCL script here is the link . If you didn’t configure eclipse for TCL then first do that because it is mandatory to configure eclipse for TCL debugging.

In this article we will see how to configure eclipse to debug TCL script . For this we would need to download Activestate’s remote debugger from this link .
On this link you will see debugger for Pearl, PHP, Paython, Ruby and TCL. We would choose TCL remote debugger for Windows. Check Screenshot below :
download TCL debugger

After downloading extract the zip package, and paste the package somewhere . Now open eclipse go to menu -> Windows -> Preferences . In preferences expand TCL->Debug -> Engines -> Active State . Go to Paths Tab -> External Debugging Engine Section . Browse to path of dbgp_tcldebug.exe which is located in package we just pasted . Check Screen below:

configure debugger with eclipseWe have successfully configured debugger . Its time to debug the TCL script. Take sample script or you can take this simple script which checks whether number is even or odd .

puts "Program to find even odd numbers"

set num 8

if { $num % 2 == 0 } {
 puts "number is even" 
} else {
 puts "number is odd " 



Save the script with some name and add breakpoint to script. Now go to Run and click on debug to start debugging. You can use different commands like Step Into , Step Over , Step Return , Resume , Terminate.

eclipse debug menuYou can use Step into to go inside in procedure and Step Over is used if you don’t want to debug the Procedure code. Resume and Terminate are used to resume program flow and Terminate current execution respectively.

For more details you can check our video tutorial on

Try to configure eclipse for debugging. You can add your comments !

How to configure Eclipse as TCL IDE

Eclipse is best IDE for development. We can use same Eclipse for development of TCL, but we will need to configure it . Dynamic Languages Toolkit (DLTK) is set of frameworks which provides Tcl, Ruby, Javascript and Python development environments.

So to configure eclipse for TCL we need to download Dynamic Languages Toolkit. In this Toolkit we have other libraries too, but we will download only for TCL. After configuration we can run program directly from Eclipse .If you want to debug TCL Program we would need to configure debugger separately .

Let’s start with configuration of Eclipse for TCL development .

1. Downlaod TCL SDK and install . If you don’t know how to install TCL on windows you can refer our last post: How to install and run TCL on this link

2. Download and Install Eclipse IDE for Java/JavaEE Developer . You can download from here

3. Start Eclipse and go to menu Help -> Install New Software . In Install window click on Add… button to add Repository details. You can give any name in Name field and add location link as  . See Screenshot for details.

install dltk
After clicking on Okay, It will show you all available packages. But for TCL we will select Dynamic Language Toolkit – TCL Developments Tools . See Screenshot for details.

Eclipse TCL Development Tools4. Click on Install and Accept License Agreement. Click on Finish and wait till Eclipse install all the required packages. After successful installation eclipse will ask to restart. Just restart the Eclipse.

5. Next step is to setup TCL interpreter with Eclipse. For this go to Menu Windows -> Preferences . On left side select TCL tab. Expand it and select Interpreter. Click on add and browse to tclsh.exe located in bin directory of installation. See screenshot.

tcl interpreter eclipse

Till now we have configured eclipse for TCL. In next step we will create TCL project.

6. To create project go to Menu File->Project-> TCL Project. (See screenshot). Give name to project and click on finish.

New Eclipse TCL Project7. To add new TCL file right click on newly created project New -> TCL File. Give name to TCL file with extension .tcl and click on finish.

8. Add some TCl lines and right click on file -> Run As -> TCL Script .

Run as TCL Script

You can see output in console window. See screenshot .

eclipse-tcl-outputYou can check our Video tutorial for installation and configuration of Eclipse for TCL on YouTube here

Try to configure Eclipse . Feel free to comment 🙂