Page 1 of 1 1
Topic Options
#74821 - 2003-05-02 06:20 PM KixStart v1.1 - Startup Script for KiXtart
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Original Topic: Passing Arguments from the Command line

This updated version also allows a batch file to run kixtart commands with out having to actually be running a kixtart script.

Examples:
kixstart @ for $counter = 1 to 10 ? $counter sleep 1 next

kixstart @ ? @scriptdir

To use:
1. Copy the code below to Notepad and save the file as Kixstart.bat in the same directory as Kix32.exe

or
1. Rename Kix32.exe to something like Kix32_420.exe.
2. Copy the code below to Notepad
3. Modify the section named ":runkix" to:
kix32_420.exe %kixscript% %cmdline%
4. Save the file as Kix32.bat in the same directory as Kix32_420.exe.
5. Run kix32 for your scripts (but with more options)

Code:


::====================================================
::STARTUP_SCRIPT KIXSTART.BAT
::
::ACTION ALLOWS USER TO PASS EITHER KIXTART ARGUMENTS
:: OR CMD LINE ARGUMENTS TO KIXTART SCRIPT
:: OR RUN A KIXTART COMMAND FROM A COMMAND PROMPT
::
::AUTHOR ALLEN POWELL (AL_PO)
::
::VERSION 1.1
::
::REQUIRES CMD.EXE FROM WINDOWS NT 4.0, WINDOWS 2000, OR WINDOWS XP
::
::SYNTAX KIXSTART SCRIPTNAME SCRIPTARGS
::OR
:: KIXSTART @ KIXTARTCOMMAND
::
::PARAMETERS
:: SCRIPTNAME - .KIX FILE
:: SCRIPTARGS - EITHER $ARG1="SOMETHING" $ARG2="NOTHING"
:: OR /A /B /C /SOMETHING /D "NOTHING"
:: OR no args at all.
::
:: KIXTARTCOMMAND - NORMAL SYNTAX OF KIXTART COMMANDS
::
::
::ADDITIONAL IF USING CMD LINE ARGS, KIXSTART.BAT SETS $CMDARGS WHICH CAN
:: BE SPLIT AND THEN PROCESSED IN THE KIXTART CODE.
::

@echo off
if not %OS%==Windows_NT goto help
if "%1"=="/?" goto help
if "%1"=="" goto help
set kixscript=%1
for /f "tokens=1* delims= " %%f in ("%*") do call :DetermineArgType "%%g"
goto end

:DetermineArgType
if %1=="" set cmdline= & goto runkix
set args=%1
set args=%args:~1,-1%
if %kixscript%==@ echo %args%>%temp%\tmp.kix & set kixscript=%temp%\tmp.kix & set cmdline= & goto runkix
if %args:~0,1%==$ set cmdline=%args% & goto runkix
if %args:~0,1%==/ set cmdline=$cmdargs="%args%" & goto runkix
goto :eof

:runkix
kix32 %kixscript% %cmdline%
goto end

:help
cls
echo 
echo.
echo KIXSTART.BAT is a startup script for KIX32.EXE.
echo.
echo KIXSTART.BAT can use EITHER kixtart arguments ($arg1="blah blah blah")
echo OR Command arguments preceded with a "/" (/a "hello" /b /c /etc)
echo OR no arguments at all.
echo.
echo To use Command arguments in Kixtart add the following to the beginning
echo of your Kixtart code:
echo.
echo if $cmdargs^<^>""
echo $params=split($cmdargs,"/")
echo for each $param in $params
echo {your code here}
echo next
echo endif
echo.
echo KIXSTART.BAT requires an NT based OS: Windows NT 4, Windows 2000, Windows XP,
echo or higher.
echo.
echo Syntax: Kixstart Scriptname ScriptArgs
echo.
:end




Top
#74822 - 2003-05-02 06:33 PM Re: KixStart v1.1 - Startup Script for KiXtart
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Allen

I like your "stuff" ... and by that I mean not just your scripts, but your fresh ideas ... stick around !

-Shawn

Top
#74823 - 2003-05-02 11:23 PM Re: KixStart v1.1 - Startup Script for KiXtart
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Thank you for the [Eek!] positive [Eek!] feedback.
[Big Grin]

This board is like a new home to me... I've finally found a place where others understand the value of a good script... [Cool]

Top
#74824 - 2003-05-03 01:18 AM Re: KixStart v1.1 - Startup Script for KiXtart
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
As long as you don't mind us taking it apart, putting it back together, nitpicking about details, and pushing your scripting abilities to the limit [Big Grin]
_________________________
There are two types of vessels, submarines and targets.

Top
#74825 - 2004-12-30 10:49 PM Re: KixStart v1.2 - Startup Script for KiXtart
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Okay here is the lastest version, which adds the ability to load a UDFLibary from the command line and use any single UDF within it. This was inspired from this thread: Pass-Through for Function calls

Example: kixstart udf.kix -f:myfunction('data')

The one problem I had adding this functionality is with text as a parameter of the fuction. Because of the way the batch files handle quotes(") it is necessary to enclose your text data with single quotes(').

Code:
 
::====================================================
::STARTUP_SCRIPT KIXSTART.BAT
::
::ACTION ALLOWS USER TO PASS EITHER KIXTART ARGUMENTS
:: OR CMD LINE ARGUMENTS TO KIXTART SCRIPT
:: OR RUN A KIXTART COMMAND FROM A COMMAND PROMPT
:: OR USE A UDF LIBRARY FROM THE COMMAND PROMPT
::
::AUTHOR ALLEN POWELL (AL_PO)
::
::VERSION 1.2
::
::REQUIRES CMD.EXE FROM WINDOWS NT 4.0, WINDOWS 2000, OR WINDOWS XP
::
::SYNTAX KIXSTART SCRIPTNAME SCRIPTARGS
::OR
:: KIXSTART @ KIXTARTCOMMAND
::OR
:: KIXSTART UDFLIBRARY -f:function(parameters)
::
::PARAMETERS
:: SCRIPTNAME - .KIX FILE
:: SCRIPTARGS - EITHER $ARG1="SOMETHING" $ARG2="NOTHING"
:: OR /A /B /C /SOMETHING /D "NOTHING"
:: OR no args at all.
::
:: KIXTARTCOMMAND - NORMAL SYNTAX OF KIXTART COMMANDS
:: UDFLIBRARY - .KIX FILE CONTAINING ONE OR MORE UDFs
::
::
::ADDITIONAL IF USING CMD LINE ARGS, KIXSTART.BAT SETS $CMDARGS WHICH CAN
:: BE SPLIT AND THEN PROCESSED IN THE KIXTART CODE.
::
:: Examples
::
:: kixstart myscript.kix /a
:: starts kix32 with myscript.kix setting $cmdargs=/a
::
:: kixstart myscript.kix -f:test('hello')
:: starts kix32 calling myscript.kix to load udf(s) and then runs the udf test passing 'hello' to it
:: NOTE: If the UDF parameter value is text, it must be enclosed with single quotes
::
:: kixstart @ for $i=1 to 10 ? $i sleep 1 next
:: starts kix32 with a temporary script displaying 1,2,3..10
::

@echo off
if not %OS%==Windows_NT goto help
if "%1"=="/?" goto help
if "%1"=="" goto help
set kixscript=%1
for /f "tokens=1* delims= " %%f in ("%*") do call :DetermineArgType "%%g"
goto end

:DetermineArgType
if %1=="" set cmdline= & goto runkix
set args=%1
set args=%args:~1,-1%
if %kixscript%==@ echo %args%>%temp%\tmp.kix & set kixscript=%temp%\tmp.kix & set cmdline= & goto runkix
if %args:~0,3%==-f: echo call "%kixscript%">%temp%\tmp.kix & echo %args:~3%>>%temp%\tmp.kix & set kixscript=%temp%\tmp.kix & set cmdline= & goto runkix
if %args:~0,1%==$ set cmdline=%args% & goto runkix
if %args:~0,1%==/ set cmdline=$cmdargs="%args%" & goto runkix

goto :eof

:runkix
kix32 %kixscript% %cmdline%
goto end

:help
cls
echo 
echo.
echo KIXSTART.BAT is a startup script for KIX32.EXE.
echo.
echo KIXSTART.BAT can use EITHER kixtart arguments ($arg1="blah blah blah")
echo OR Command arguments preceded with a "/" (/a "hello" /b /c /etc)
echo OR no arguments at all.
echo.
echo To use Command arguments in Kixtart add the following to the beginning
echo of your Kixtart code:
echo.
echo if $cmdargs^<^>""
echo $params=split($cmdargs,"/")
echo for each $param in $params
echo {your code here}
echo next
echo endif
echo.
echo KIXSTART.BAT requires an NT based OS: Windows NT 4, Windows 2000, Windows XP,
echo or higher.
echo.
echo Syntax: Kixstart Scriptname ScriptArgs
echo.
:end


Top
#74826 - 2004-12-31 08:28 PM Re: KixStart v1.2 - Startup Script for KiXtart
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
After posting this latest version, I got to thinking and realized the new option to load UDFs is not limited to just one function. In fact it is possible to use just about any command in kixtart from the command line now.

For example:

I created a simple UDFLibrary with just one UDF in it:
test.kix
Code:
 

function echo($output)
$echo=$output
endfunction



Then using the syntax of kixstart.bat:
Code:

kixstart test -f:echo('Hello World')


would display: Hello World

But, there is nothing stopping me from typing in this too.
Code:

kixstart test -f:$=echo('Hello World') ? $ ? join(split($,'Hello'),'Goodbye')


would display: Hello World, Goodbye World


Obviously this is exceptionally prone to typos, so use with care. HTH.

Top
#214297 - 2025-02-14 05:37 AM Re: KixStart v1.2 - Startup Script for KiXtart [Re: Allen]
Comet Offline
Just in Town

Registered: 2025-02-07
Posts: 4
Loc: California, United States of A...
Thank you for your script that takes one line of command input interactively, and executes it. Read=Evaluate-Print

Placing this in a loop is one means of making KiX interactive REPL.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 323 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.035 seconds in which 0.011 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