Page 1 of 1 1
Topic Options
#193000 - 2009-03-19 05:50 PM Combine BAT/CMD and KIX into one file
Albertane Offline
Just in Town

Registered: 2009-03-19
Posts: 3
Loc: Eagan, MN, USA
I didn't see how to do this anywhere so I figured it out myself. I figured I should post it so it might be of use to others.

I often write short scripts that I would like to be able to be run just by double clicking on a computer that might not have file associations set up to run Kixtart when double-clicking a KIX file. In the past, I've had to make a CMD file to go along with each KIX file that would start kix32.exe and run the KIX file. This method combines both files into one so that you can just double-click on a BAT or CMD file that starts kix32.exe and runs itself. The BAT commands are ignored by KiXtart and the KiXtart commands are ignored by the command interpreter.

Put this in a file with a BAT or CMD extension:
 Code:
;@echo off
;echo This is a batch file command.
;"%~dp0\kix32.exe" "%~f0" %*
;pause
;exit

? "This is a KiXtart command."
?


KIX32.EXE must be in the same directory as the CMD file. If not, change the %~dp0 to the path of KIX32.EXE. Delete the ";pause" line if you don't want "Press any key to continue" to be shown after the script is finished.


Edited by Albertane (2009-03-19 10:12 PM)

Top
#193004 - 2009-03-19 05:58 PM Re: Combine BAT/CMD and KIX into one file [Re: Albertane]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4350
Loc: New Jersey
Interesting... kind of like specifying the desired shell intepreter in a Unix script.

You might want to simply pass %* instead of the individual 10 args.

Gonna have to play with this one, just for the technical merit. \:\)

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

Top
#193005 - 2009-03-19 05:59 PM Re: Combine BAT/CMD and KIX into one file [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4350
Loc: New Jersey
Oh, and Welcome to KORG!
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193014 - 2009-03-19 08:54 PM Re: Combine BAT/CMD and KIX into one file [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11611
Loc: CA
It should work quite well Glenn. Basic batch stuff there. To be honest though I can't recall in almost 10 years now of doing this that I've done more than a very basic edit or run of "test" scripts on another box beyond my own.

Thanks for sharing though as I'm sure there are other users such as yourself that may do it or have a need for it. Versatility is always nice.

Top
#193018 - 2009-03-19 10:03 PM Re: Combine BAT/CMD and KIX into one file [Re: Glenn Barnas]
Albertane Offline
Just in Town

Registered: 2009-03-19
Posts: 3
Loc: Eagan, MN, USA
 Originally Posted By: Glenn Barnas
Interesting... kind of like specifying the desired shell intepreter in a Unix script.

Exactly. That's where I got the idea.

 Originally Posted By: Glenn Barnas
You might want to simply pass %* instead of the individual 10 args.

I was thinking there was something like that. I should have just tried it. I'll change my original post.

I also realized there's a bug too. %0 doesn't expand to include the file extension if you run the batch file from a command line. Using %~f0 instead fixes that.


Edited by Albertane (2009-03-19 10:05 PM)

Top
#193019 - 2009-03-19 10:08 PM Re: Combine BAT/CMD and KIX into one file [Re: NTDOC]
Albertane Offline
Just in Town

Registered: 2009-03-19
Posts: 3
Loc: Eagan, MN, USA
 Originally Posted By: NTDOC
It should work quite well Glenn. Basic batch stuff there. To be honest though I can't recall in almost 10 years now of doing this that I've done more than a very basic edit or run of "test" scripts on another box beyond my own.

I've written a lot of little scripts to fix things on people's computers. So I have a directory on one of our file server with a bunch of .CMD/.KIX file pairs. Now I can get rid of half of those files.

Top
#193020 - 2009-03-19 11:39 PM Re: Combine BAT/CMD and KIX into one file [Re: Albertane]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4350
Loc: New Jersey
Just don't tokenize them \:o

G-
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193022 - 2009-03-20 12:09 AM Re: Combine BAT/CMD and KIX into one file [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11611
Loc: CA
I have that too, but all I do is drag the script and drop it onto KIX32.EXE and it runs just the same. No command line needed.

But I consider those "production" scripts and not per say my own "testing" scripts.

Top
#193252 - 2009-03-30 02:31 PM Re: Combine BAT/CMD and KIX into one file [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4350
Loc: New Jersey
OK - had to modify this a bit to get it to work the way I want, but does eliminate the batch file. \:\) My KGen tool required a bat file to pass the 2 optional args in a specific way. Here's how I changed KGen.kix to KGen.bat:
 Code:
;@echo off
;kix32.exe "%~f0" $A1=%1 $A2=%2
;Goto END

;; kgen - generate a kix script, automatically locating and including all required UDFs
<kgen code goes here...>
:END

Since KGen is a command line based UDF resolver, I could not use the ;Exit command or it would close the window where I was working. Kix tolerates the label as its own, so it works fine with a ;Goto END. Also, I use a scripts folder where both this tool and the Kix.exe's live, and it's in my PATH, so I did not need to use the "%~dp0" var.

I don't have too many bat/kix pairs left, since most systems that rely on Kix scripts have the exe in the path or run via scheduled task and I make heavy use of the GetCommandLine function now, but there's a few scripts that this will help. This one especially since the dev systems where this runs always has the tools in the PATH.

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

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
1 registered (Allen) and 285 anonymous users online.
Newest Members
Praveer, Ollero, rayyo, Foxlicht, DonChild
17742 Registered Users

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