#138357 - 2005-04-21 08:51 AM
retrieve executed script line number
|
oneYogi
Fresh Scripter
Registered: 2005-04-13
Posts: 6
|
Goodday to you all.
Is it possible to retrieve the current executed script line number in a working script, like when a script has an error in it and kixtart would echo the last read line with the error in it? I would love to add this info in some logging tools....
Kind regards Yogi
|
|
Top
|
|
|
|
#138359 - 2005-04-21 02:55 PM
Re: retrieve executed script line number
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Yogi,
Welcome to the board!
One of the things that KiXtart does do at the time of execution, it will try to tell you what the error is.
Another thing to think about is how you code. That is proper indenting. If you have an IF, you need a corresponding ENDIF. And the statements inside it should be nested to be easily spotted for structure.
Another way to do this is to get a copy of KiXStrip and run your script through it.
For example: Code:
CLS BREAK ON IF EXIST('C:\BOOT.INI') ?'DOES EXIST' GET $
And I get for a result: Code:
CLS BREAK ON IF EXIST('C:\BOOT.INI') ?'DOES EXIST' GET $
;($begin) ; ; thu 21-apr-2005 05:42:38 (kix 4.20 vs 4.00e) ; ;Informative KIXSTRIP: input=5 output=5 skip=0 ; ;Warning KIXSTRIP: 1 error in block structure. missing statement(s). ; - do:until [0:0] ; - for|each:in|to:step|next [0|0:0|0:0|0] ; - function:endfunction [0:0] ; -ERROR- - if:else:endif [1:0:0] ; - select:case:endselect [0:0:0] ; - while:loop [0:0] ;Warning KIXSTRIP: some lines contains errors or possible errors. ;Informative KIXSTRIP: 1 block_structure found. ;Informative KIXSTRIP: no UDF's found. ;Informative KIXSTRIP: no labels found. ;Informative KIXSTRIP: 1 BREAK ;Informative KIXSTRIP: 1 GET ; ;($end) ;($begin) ; ;
HTH,
Kent
|
|
Top
|
|
|
|
#138360 - 2005-04-21 03:03 PM
Re: retrieve executed script line number
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Kent,
That's not what he's after. He's wanting to include the line number in logging / diagnostic output when the script is in production. Something like: Code:
If $sMyVariable="" Log("["+@SCRIPT+"/"+@SCRIPTLINE+"] sMyVariable unexpectedly blank! Processing continues..") EndIf
|
|
Top
|
|
|
|
#138362 - 2005-04-21 03:21 PM
Re: retrieve executed script line number
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Actually, he said "like when a script has an error in it and kixtart would echo the last read line with the error in it".
Exactly, and he wants this facility because "I would love to add this info in some logging tools...."
If you are still in control you could be more explicit and log "I'm in section foo of script bar" or whatever, but if you are generating output to a log file it's simpler and more readable to use a common prefix to the log entry such as a timestamp, script name and line number.
I haven't tried tokenised scripts yet, so I can't comment on whether line counts are preserved.
|
|
Top
|
|
|
|
#138363 - 2005-04-21 03:29 PM
Re: retrieve executed script line number
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Just tried with a tokenised script, and the line count is preserved: Code:
C:\Temp>c:\windows\kix32.exe err.kx
ERROR : array reference out of bounds! Script: err.kx Line : 3
|
|
Top
|
|
|
|
#138364 - 2005-04-21 04:09 PM
Re: retrieve executed script line number
|
oneYogi
Fresh Scripter
Registered: 2005-04-13
Posts: 6
|
Thank you all for your comments.
Richard, I thought so, and will post the suggestion. I came about this when I used the copy command and recieved no output (while it also didn't do what I wanted...), thus I am writing a function at the moment with nice logging features, one of which is the location of the caller..... but I'll have to send that as a comment in a parameter (already built in).
When the function is completed, I will post it here as well....( or should it be to another forum as it ain't starters info?)
Thank you Kent for the welcome and tips (kixstrip), I do all those wonderful indenting stuff already (not that much of a starter..), just had to register to be able to search :-( and post :-D --> with great results!
Thank you all again!
Regards Yogi
|
|
Top
|
|
|
|
#138366 - 2005-04-21 06:51 PM
Re: retrieve executed script line number
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Quote:
I came about this when I used the copy command and recieved no output (while it also didn't do what I wanted...),
Hi Yogi, since as you say you're not too much a noob that's cool so I'll just say that KiXtart along with most other scripting languages has limits on what can be handled. As I'm sure you know like Les says, if KiX coughs on the code you get nothing (unless you're interactively running it from a DOS console) Beyond that most scripters seem to just write the code and run it and hope for the best, once it doesn't seem to work as they want then they either run their script with the /D (debug) command and walk through it, or place DEBUG code into the script and watch the output to find where the script has gone askew.
Typically stuff like ? 'Got to line# n ' + @ERROR + ' ' + @SERROR or similar output to help locate the problem.
Then once the code is functioning as you would like and if you're logging stuff you would place in certain @ERROR checks so that they could be logged using some type of other data that would help you to know what and where the script went askew. Sorry but without a ton of bloat currently don't think there is a method to give actual line number into the log (nice suggestion though that goes along with the request for ONERROR RESUME, which has also not been implemented yet). But remember that if the error is severe enough to crash the KiX executable then you will have no log of any type either.
Good luck and post the completed script to the SCRIPTS forum where we can comment on the code or help to improve it if needed or possible.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1003 anonymous users online.
|
|
|