Page 1 of 1 1
Topic Options
#138357 - 2005-04-21 08:51 AM retrieve executed script line number
oneYogi Offline
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
#138358 - 2005-04-21 09:09 AM Re: retrieve executed script line number
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Simple answer is no, there is no way to do this.

It's worthy of a post in the "suggestions" forum though. A Macro like @SCRIPTLINE which returns the line count would be a useful addition for debugging / error messages.

Top
#138359 - 2005-04-21 02:55 PM Re: retrieve executed script line number
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#138360 - 2005-04-21 03:03 PM Re: retrieve executed script line number
Richard H. Administrator Offline
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
#138361 - 2005-04-21 03:08 PM Re: retrieve executed script line number
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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". If the script has an error in it, and KiX chokes on the error, the script no longer has control anyway so you get only what KiX gives you.

If, on the other hand, you are still in control of the execution, then the error logging logic would know where it is and could send the pertinent info to the log. Actual line number may have little meaning if the script was tokenized.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138362 - 2005-04-21 03:21 PM Re: retrieve executed script line number
Richard H. Administrator Offline
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 Offline
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 Offline
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
#138365 - 2005-04-21 04:15 PM Re: retrieve executed script line number
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If you have a (finished) script that you want to discuss or get more help with then post it to the Scripts forum.

If you have general queries about KiXtart or you are not sure which forum to use then post to the starters forum.

Top
#138366 - 2005-04-21 06:51 PM Re: retrieve executed script line number
NTDOC Administrator Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1188 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.062 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org