Page 1 of 1 1
Topic Options
#196277 - 2009-10-07 10:12 AM Tokenized scripts identification
BoForce Offline
Fresh Scripter
**

Registered: 2005-10-22
Posts: 36
Loc: Leeuwarden, The Netherlands
Hi guys,

Did I make a clasic mistake.

When 4.61 was relased I decided it was time to run our logon script with the new version instead of 4.53. So I tokenized the script with 4.61, but forgot to replace the 4.53 version with 4.61. This resulted in an error. It took me only a few minutes to figure out what was wrong and after a little browsing within the KORG board I found out that this was to be expected.

Suggestion:
Is it possible to have to tokenize process set a flag or whatever other identification possible to the .kx file?

Top
#196281 - 2009-10-07 11:46 AM Re: Tokenized scripts identification [Re: BoForce]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
What was the error?

If your script is version specific (because it is tokenised) why not just include the interpreter version in the script name?

For example, myscript.kix compiled with KiXtart 4.61 becomes myscript.kx - you rename it as myscript_461.kx or myscript.461 or whatever else fits.

Or are you suggesting something else?

Top
#196283 - 2009-10-07 12:09 PM Re: Tokenized scripts identification [Re: Richard H.]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
I did a little digging into this with Ruud. He was surprised that scripts tokenized with 4.53/4.60 failed with 4.61.

If you have a simple script and tokenize it with an earlier version, it WILL run with 4.61. However, it seems that if you have any type of COM defined, it fails.

I ran a bunch of tests after my login script failed, and it seems that just about every kix function will work, but include WshPipe(), or ADSIUserInfo() and it will die.

I did not test the opposite, but based on Ruud's comments, I'd bet it is a similar situation. I'll run my set of tests in reverse and let you know what I find.

I left this info for Ruud in a PM a while back. I now tokeninze my script with both Kix versions when I distribute my login script.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196285 - 2009-10-07 12:58 PM Re: Tokenized scripts identification [Re: BoForce]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Here's a short version of the test script, after narrowing down the problem to be references to objects.
 Code:
;; KixGenerated: 2009/09/25 06:48:27
Break On

@Kix ?

ReadValue('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\devices', 'Fax') ?

Test('farkle')

Ping('127.0.0.1')

Function Test($Arg)

  'Arg is ' $Arg ?

EndFunction


;;
;;======================================================================
;;
;;FUNCTION       ping()
;;
;;ACTION         ping - Pings a host
;;
;;AUTHOR         Glenn Barnas
;;
;;VERSION	 2.0 - 2007/10/20 - WHS version
;;		 1.0 - based on KORG Ping UDF by Jochen Polster, enhanced to 
;;			return values and IP's
;;
;;SYNTAX         ping(host, [Flag], [Wait])
;;
;;PARAMETERS     host - name of host to ping
;;               FLAG - if negative, returns IP Address
;;                      if >0, specifies number of tries (default is 1)
;;               Wait - optional ping timeout value
;;               
;;
;;REMARKS        ERROR is set to 0 if success, 1 otherwise.
;;
;;RETURNS        FLAG >= 0: returns 1 if host is reachable, 0 if not
;;               FLAG <  0: Returns IP address if resolvable, 0.0.0.0 if not
;;
;;DEPENDENCIES   OS Commands Ping & Find
;;
;;TESTED WITH    NT4, W2K, WXP
;;
;;EXAMPLES       Ping('hostname')       ; returns Success/Failure
;;               Ping('hostname',-1)    ; returns IP Address
;
Function Ping($_Host, OPTIONAL $_Flag, OPTIONAL $_Wait)

  Dim $_oExec				; WSH Object
  Dim $_Tries				; # of times to ping
  Dim $_Timeout				; Ping timeout value
  Dim $_Response			; Response Flag
  Dim $_Line				; Line returned from command string
  Dim $_Cmd				; first part of command string
  Dim $_Count				; current ping count

  $_Flag    = Val($_Flag)		; determine what to do
  $_Wait    = Val($_Wait)		; 
  $_Tries   = 1				; one ping
  $_Timeout = 1000			; 1 second timeout

  ; set timeout if Wait is non-zero
  If $_Wait > 0
    $_Timeout = $_Wait
  EndIf

  If $_FLAG > 0        ; Multiple pings - return on first reply
    $_Tries = $_FLAG
  EndIf

  ; Ping the host $_Tries times, but only until a response is received
  $_Count = 0

  ; search for reply from host during PING
  $_Cmd = '%COMSPEC% /c ping.exe -4 -n 1 -w ' + $_Timeout + ' ' + $_Host 
  If $_Flag < 0
    $_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Pinging"'
  Else
    $_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Reply" | %SystemRoot%\System32\Find "TTL="'
  EndIf
  Do
'w'
    $_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
'x'
    If Not VarType($_oExec)=9 $Ping = 'WScript.Shell Exec Unsupported' Exit 10 EndIf
'y'
    $_Line = Split(Join(Split($_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll,CHR(13)),''),CHR(10))[0]
'z'
    $_Response = IIf($_Line, 1, 0)
    If $_Response
      $_Count = $_Tries
    EndIf
    $_Count = $_Count + 1
    If $_Count <  $_Tries Sleep 0.25 EndIf
  Until $_Count >= $_Tries

  ; If FLAG >= 0, return success/failure - otherwise return IP address
  If $_FLAG >= 0
    $Ping = $_Response
  Else
    If Not $_Response
      $Ping = '0.0.0.0'
    Else
      ; In this mode we return the IP address - we should have the HOSTNAME
      ; handle the 'duh' factor for times when we get the IP address instead!
      If InStr($_Line,'[') > 0
        $Ping= Split(Join(Split($_Line,']',-1),'['), '[')[1]
      Else
        $Ping = Split(Split($_Line,' ',-1)[1], ':')[0]
      EndIf
    EndIf
  EndIf

  Exit Not $_Response       ; set the error code

EndFunction
Note that the Ping function is modified to display "wxyz" to monitor progress through the function. Tokenizing with 4.53 works with 4.60 but not 4.61. Tokenizing with 4.61 works with 4.61 but not with earlier releases. In either case, the error returned is
 Code:
G0PW01 - K:\KixBinaries>kix324.53 t.kx
4.53
winspool,Ne01:
Arg is farkle
wx
ERROR : IDispatch pointers not allowed in expressions!
Script: K:\KixBinaries\t.kix
Line  : 90
From the fact that it displays "wx", you can see that the $oExec COM instantiation does not fail, but apparently does not return a proper value any longer, failing on the If Not VarType($_oExec)=9 line.

My login script displays an "invalid method/function call: too many parameters! yet references a block of comments as the offending line. Still haven't got to the bottom of that, yet, but have almost 3000 lines to work through.

Ruud says he didn't make any changes in the tokenizing components, so this is unexpected behavior, even though tokenizing isn't technically supported across Kix versions.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196286 - 2009-10-07 01:06 PM Re: Tokenized scripts identification [Re: Richard H.]
BoForce Offline
Fresh Scripter
**

Registered: 2005-10-22
Posts: 36
Loc: Leeuwarden, The Netherlands
The error is that it is missing a ')' in line:

 Code:
$cloLoggingOrderColl = Split(ReadValue($_ini,"Logging Options","Logging Order"),';')


I never documented the version used for tokenized scripts as I've started using this from version 4.53 and have been using 4.53 since three years now.
When I found out that it can fail, I adjusted my documentation regarding tokenizing kix script within our company.
Besides documenting it, I've also added 4.61 to the Keywords within the properties of a .kx file.

Adding the version of Kix32 into the name of the script is a good suggestion.

Top
#196287 - 2009-10-07 01:28 PM Re: Tokenized scripts identification [Re: Glenn Barnas]
BoForce Offline
Fresh Scripter
**

Registered: 2005-10-22
Posts: 36
Loc: Leeuwarden, The Netherlands
Thanks for explaining it to me.

 Quote:
I ran a bunch of tests after my login script failed, and it seems that just about every kix function will work, but include WshPipe(), or ADSIUserInfo() and it will die.

I can confirm that I use WSHPipe() within the script.

 Quote:
Ruud says he didn't make any changes in the tokenizing components, so this is unexpected behavior, even though tokenizing isn't technically supported across Kix versions.

I have learned my lesson from this issue and will be more carefull in the future.
The reason I started this post is to find out if anything would be possible to prevent this from happening again.
As I replied earlier I've adjusted the documentation for scripting within our company and have taken several other actions,
but that doesn't make it fail proof.

 Quote:
My login script displays an "invalid method/function call: too many parameters! yet references a block of comments as the offending line. Still haven't got to the bottom of that, yet, but have almost 3000 lines to work through.

I know. My login script has 6704 lines and if Kix is missing something (in my case a ')' at line 4514) it doesn't mean that the typo is near 4514,
but it could also be 50 or 100 lines before. Where to start.

Top
#196393 - 2009-10-17 02:35 PM Re: Tokenized scripts identification [Re: BoForce]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
 Originally Posted By: BoForce

I know. My login script has 6704 lines and if Kix is missing something (in my case a ')' at line 4514) it doesn't mean that the typo is near 4514,
but it could also be 50 or 100 lines before. Where to start.


In this case, you will need a parser or indenter.. There are a few of them around here including MCA's KiXStrip (there is a flash from the past!) that can re-assemble your script and should point out where your missing missing parenthesis is. Also, any good Editor like: Ultraedit, EditPad will do "Bracket Matching" and thet will show where you have a missing quote, parenthesis, etc. as well. Good stuff! Another way to do this is to start breaking your script out into functions and start peeling back the layers of the onion and that can also help as well..

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#196394 - 2009-10-18 01:48 AM Re: Tokenized scripts identification [Re: Kdyer]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Kent,

The problem isn't a missing paren - the code is fine. It's all about running scripts tokenized with 4.53 or 4.6 with 4.61.

My example passes a Sanity() test, and works with prior Kix versions. When called from Kix 4.61, it throws an error that is meaningless - in this example, a missing closing paren. The script does work flawlessly with 4.61 if it isn't tokenized.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


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

Who's Online
0 registered and 579 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.058 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

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