Printing the line number.
Posted by skumar003 (skumar003), 7 April 2003I 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 2003The 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 2003You 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:
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho