Page 1 of 1 1
Topic Options
#175348 - 2007-04-12 02:15 AM getcommandline() trouble
JethroF Offline
Lurker

Registered: 2007-04-11
Posts: 1
I've written quite a few KiX scripts but have never needed to pass an argument into the script before. I'm now trying to pass arguments into a script and have been trying to use the getcommandline() function as mentioned in the release notes for v4.52.

When testing how to use this function in a very basic script that only echos the command line back I continue to get errors.

 Code:
; test.kix
$CommandLine=GetCommandLine(0)
'The command is '$CommandLine ?


When launching my test script using the command line:
kix32.exe test.kix hello

I get the following output:
The command is kix32.exe test hello
ERROR : failed to find/open script [hello]!

It's as if KiX isn't realizing this is a variable I'm passing in and is trying to run it as an additional script after it finishes the first script.

I get the same result using either v4.52 or v4.53.

There's precious little mention of the getcommandline() in the release notes and nothing in the manual (http://www.kixtart.org/manual/).

What am I missing here? How do I get rid of this error?
Any pointers on how to pass an argument into a script?

Top
#175349 - 2007-04-12 02:25 AM Re: getcommandline() trouble [Re: JethroF]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
Unfortunately, this is by design. However, please see the following thread as there are at least two methods to get around it.

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=170448&page=1#Post170448
_________________________
(... better days ahead)

Top
#175350 - 2007-04-12 02:26 AM Re: getcommandline() trouble [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA
BTW... the normal method to send a variable into kix is

kix32.exe scriptname $var="Blah"

This is in the manual.
_________________________
(... better days ahead)

Top
#175351 - 2007-04-12 03:48 AM Re: getcommandline() trouble [Re: JethroF]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Here's something to play with - save this as GetArg.kix:
 Code:
Break On

'GetArg - ' @KIX ? ?

; $ARG can be passed on the command line, 
; or can be gathered by the GetCommandLine() function

; $ARG will be declared (Global) if it was passed on the command line
If IsDeclared($ARG)
  'ARG passed' ?
Else
  If CDbl(@KIX) < 4.53
    "Can't enumerate args in Kix v" @KIX ?
    Quit 0
  EndIf

  Global $ARG
  'ARG captured by GetCommandLine' ?

  ; Parse the command line
  $CommandLine = GetCommandLine(1)

  ; Complain and exit if no arguments were specified.
  If UBound($CommandLine) = 1
    'No input arguments were specified.' ?
    Quit 1
  EndIf

  ; Have arguments - build a comma-delimited list for this example
  $ARG = ''
  $Sep = ''
  For $I = 2 to UBound($CommandLine)
    $ARG = $ARG + $Sep + $CommandLine[$I]
    $Sep = ','
  Next
EndIf

'ARG: ' $ARG ?

Quit 0           ; needed if passed args don't have - or / predecessors


Try this running "kix32 GetArg.kix $ARG='a,b,c'", and then again running "kix32 GetArg.kix -a -b -c". Try it again without the leading "-" chars on the args. Try including "-d" and see what happens. Try the examples again without the "Quit 0" at the end of the script.
This should illustrate the capabilities and limitations of the GetCommandLine() function.

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

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 840 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.051 seconds in which 0.024 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