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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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:
http://www.wellho.net/book/0-201-63337-X.html






This page is a thread posted to the opentalk forum at www.opentalk.org.uk 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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho