Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Printing the line number.

Posted by skumar003 (skumar003), 7 April 2003
I a m sourcing a file to do some stuff  and I primarily do a regexp x expect_out_buffer.

If it matches I return a Pass and else I Fail.

Is there a way to return the line number in the script when it fails.

Like a standard synatx to print the line number in the script where it failed.

Posted by admin (Graham Ellis), 8 April 2003
The return command lets you return an integer value as the error code from a procedure, top level command or (as in your case) a source command.   I would suggest you use this to return - for example:
       return -code 27
to return error code 27.

It might be possible to work out the line number, but if you use that you'll find that every time you add a line to your sourced file the return valuse change, and your code would be very hard to maintain.

Posted by skumar003 (skumar003), 8 April 2003

How can I be able to print the line number? I agree with you in change in return code every time additional lines are added .

But It would help in my application.

Lust like the TCL report serror at line number I need to be able to pinpoint line numbers when a failure occurs.

Posted by admin (Graham Ellis), 9 April 2003
You can get the error code and error description from the latest Tcl error from the global errorCode and errorInfo variables, you can use the catch and error commands to provide you with some control over these, and you can use commands such as info cmdcount to return a count of the number of commands invoked by the interpretter.  

If there was a separate way of saying "what line am I at" it would be pretty pointless - just assigning a variable to a unique code number is just as effective and doesn't change as you develop your code;  I continue to have a strong suspission that you're looking for a facility that hasn't been provided in the way you want in Tcl because the Tcl authors knew it would entice people to follow bad programming practice ....

If you're using expect and looking to find out where an interaction fails, can I suggest that you turn log_user on; that way, you'll see where your process hangs.

The trace command, which lets you see every time a variable is read or written, may also be of help.

Finally, if you're a C programmer you might wish to explore onbe layer deeper into Tcl - a reference such as John Ousterhout's book will help you much more with this than I can:

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho