#177976 - 2007-07-16 02:07 PM
Re: Passing parameters from environment ?
[Re: Glenn Barnas]
|
MACE
Starting to like KiXtart
Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
|
Thanks one and all. Could not get to work the traditional method as not all values were passing. The GetCommandLine() is new to me and now I am aware of it it is the best tool for the job. I am sure I can proceed with this help.
EDIT >>
The registry comment is VERY pertinant. It is in fact not KIX which is the problem but the fact it is NOT getting the parameters in the first place.
I have been using the following registry setting to envoke kix:(This is written on setting up each PC during logon script once wkix32 is installed.)
$ = WRITEVALUE ("HKEY_CLASSES_ROOT\KX_auto_file\shell\open\command", "", '%SystemRoot%\system32\wkix32.exe "%1"', "REG_SZ")
I have tried today the following... $ = WRITEVALUE ("HKEY_CLASSES_ROOT\KX_auto_file\shell\open\command", "", '%SystemRoot%\system32\wkix32.exe "%1" %2 %3 %4 %5 %6 %7 %8 %9', "REG_SZ")
and
$ = WRITEVALUE ("HKEY_CLASSES_ROOT\KX_auto_file\shell\open\command", "", '%SystemRoot%\system32\wkix32.exe "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9"', "REG_SZ")
If I have a command line as follows: WKIX32.EXE MYSCRIPT.KIX PARAMETER the script runs, passes the parameter correctly but on exiting the script KIX then tries to run a script per the value of PARAMETER and errors as of course the script does not exist.
If as is intended I have a command line as follows: MYSCRIPT.KIX PARAMETER
ERROR: Failed to open/find script [2]!
The start of the MYSCRIPT.KIX script is as follows...
$CL=GetCommandLine(0) If IsDeclared($CL) $CL=GetCommandLine(1) $X = UBound($CL) $ = MYFUNCTION($CL[$X]) EndIf
Here $X is returning 2 but $CL[2] does not exist ?
Can anyone offer suggestions on 1] how to sort out the registry settings and 2] let kix actually read the correct value of command line parameters. ( If I use SPLIT on the GetCommandLine(0) I could achieve the desired result but does not help until I can successfully pass a full command line without it erroring either on entry or exit.)
Edited by MACE (2007-07-16 04:11 PM)
|
|
Top
|
|
|
|
#177983 - 2007-07-16 05:58 PM
Re: Passing parameters from environment ?
[Re: MACE]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
It has something to do with how Kix32.exe handles arguments.
"Kix32 script1 script2 script3" is valid, and will cause the 3 scripts to be executed in sequence. If "script2" is actually an argument, and isn't processed/understood by Script1, then kix32 assumes it is a script, and complains when it can't find it. Exits with status 2 (file not found).
You can circumvent this by exiting Script1 with QUIT 0 instead of EXIT 0. This terminates the current and all following scripts. Not always a clean or convenient process, though. The true fix is to make sure Kix treats your script args properly, passing them to the script and not using them directly.
I've found it's really important to use "--" or "//" to identify kix SCRIPT arguments. When Kix sees the leading "-" or "/", it knows not to process it as a script name. The need to double the argument identifier prevents kix from seeing "-download" as "-d" and invoking debug mode! Remember, kix32 runs and interprets the command line FIRST. It accepts "unadorned" args as script names, and anything beginning with "-" or "/" as a potential modifier. It will use them itself, even though it passes all the args to your script. Thus, you often get unwanted results.
Bottom line "Kix32 MyScript filename" will usually fail because "filename" can't be found, or isn't a script. "kix32 MyScript --f:filename" will work, because kix32 knows to pass it to the script. Of course, you need to verify the "--f:" part and Split on the ":" to get the filename. More up-front work, but much higher reliability.
"kix32 MyScript -download" will invoke kix debug mode, while "kix32 MyScript --download" will run normally.
Hope this helps.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#178005 - 2007-07-17 01:40 PM
Re: Passing parameters from environment ?
[Re: MACE]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Yes, that is the literal registry configuration!
I don't use "GetCommandLine(0)" - only "GetCommandLine(1)", returning the array. With your code on my system, I get:
COMPUTER - C:\Temp>mart -1 -2 -3
"C:\local\bin\kix32.exe" "C:\Temp\mace.kix" -1 -2 -3
Parameters 0="C:\local\bin\kix32.exe"
Parameters 1="C:\Temp\mart.kix"
Parameters 2=
Parameters 3=-1
Parameters 4=-2
Parameters 5=-3
Last Parameter = -3
But changing $CL=split(GetCommandLine(0)," ") to $CL = GetCommandLine(1) returns:
COMPUTER - C:\Temp>mart -1 -2 -3
"C:\local\bin\kix32.exe" "C:\Temp\mace.kix" -1 -2 -3
Parameters 0=C:\local\bin\kix32.exe
Parameters 1=C:\Temp\mart.kix
Parameters 2=-1
Parameters 3=-2
Parameters 4=-3
Last Parameter = -3
Which seems to be more what you want, isn't it?
I removed the Quit() from the end for this test, which should really be "Quit 0" if you actually need it. Also - I don't understand the "IsDeclared(CL)" statement. You're implicitly declaring it with the statement $CL=GetCommandLine(0), so that test will always be true.
If you look at my code, I'm using IsDeclared to determine if a var called ARG was passed on the command line (kix32 MyScript $ARG=xxx). If it wasn't, than $ARG is created via the GetCommandLine function. You can simplify your code to:
break on
; Illustrate the full command line string
'Comand line is: ' GetCommandLine(0) ?
; Load the Command Line array
$CL = GetCommandLine(1)
; Show count of args
UBound($CL) - 1 ' arguments were passed' ?
; process the args if any were passed
If UBound($CL) - 1
for $X = 2 to UBound($CL)
"Parameter " $x-1 "=" $CL[$X] ?
next
"Last Parameter = "+$CL[UBound($CL)] ?
EndIf
Try this without args, with "tom dick harry" as args, then repeat the command line with single and then double "-" in front of each arg. You'll get 3 different results! First will complain that the script Tom isn't found (no Quit 0), then it will see the "T" in "Tom" and try to tokenize "Dick". Finally, it will pass ALL of the args to the script without error or complaint.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#178015 - 2007-07-17 05:36 PM
Re: Passing parameters from environment ?
[Re: Allen]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
The parameters starting with slash or dash are free
|
|
Top
|
|
|
|
#178042 - 2007-07-18 01:45 PM
Re: Passing parameters from environment ?
[Re: MACE]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
I use the Associate() UDF when defining the registry keys. Here's the prep code from my script that updates the registry via Associate().
FYI - $BinPath is where the Kix32 exe's are placed; $KIXEDITOR is "notepad.exe", but can be your favorite Kix editor - just so there's no mystery.
The Associate UDF does all the housekeeping needed to create Open and Edit command definitions for a particular file extension. It's posted here on KORG (and part of the KixDev package on my web site). The real point here is to show how I assembled the Open registry value. The problem is that "%" has special meaning, and will be interpreted by Kix32 as an environment value. You should use "%%" instead of "%" so Kix will ignore it. Thats why I used Chr(37) in the example below.
Glenn
;Define the executables to associate with OPEN and EDIT functions
; Modified to pass all args to support V4.53 GetCommandLine()
; KiXtart Command Line Scripts - Kix32.exe "%1" %*
$KXOPEN = $BinPath + '\kix32.exe ' + CHR(34) + Chr(37) + '1' + CHR(34) + ' ' + Chr(37) + '*'
; KixForms GUI Scripts
$KWOPEN = $BinPath + '\Wkix32.exe /I ' + CHR(34) + Chr(37) + '1' + CHR(34) + ' ' + Chr(37) + '*'
; Editor for all non-tokenized KiXtart scripts
$KXEDIT = $KIXEDITOR + ' ' + CHR(34) + Chr(37) + '1' + CHR(34)
Associate('.KIX', 'KixScript', 'Kixtart Script', $KXOPEN, $KXEDIT, 0)
Associate('.KX', 'KixTokenizedScript', 'Kixtart Script', $KXOPEN, '', 0)
Associate('.KXW', 'KixWScript', 'Kixtart GUI Script', $KWOPEN, $KXEDIT, 0)
Associate('.KW', 'KixTokenizedWScript', 'Kixtart GUI Script', $KWOPEN, '', 0)
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 764 anonymous users online.
|
|
|