Albertane
(Just in Town)
2009-03-19 05:50 PM
Combine BAT/CMD and KIX into one file

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.


Glenn BarnasAdministrator
(KiX Supporter)
2009-03-19 05:58 PM
Re: Combine BAT/CMD and KIX into one file

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


Glenn BarnasAdministrator
(KiX Supporter)
2009-03-19 05:59 PM
Re: Combine BAT/CMD and KIX into one file

Oh, and Welcome to KORG!

NTDOCAdministrator
(KiX Master)
2009-03-19 08:54 PM
Re: Combine BAT/CMD and KIX into one file

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.


Albertane
(Just in Town)
2009-03-19 10:03 PM
Re: Combine BAT/CMD and KIX into one file

 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.


Albertane
(Just in Town)
2009-03-19 10:08 PM
Re: Combine BAT/CMD and KIX into one file

 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.


Glenn BarnasAdministrator
(KiX Supporter)
2009-03-19 11:39 PM
Re: Combine BAT/CMD and KIX into one file

Just don't tokenize them \:o

G-


NTDOCAdministrator
(KiX Master)
2009-03-20 12:09 AM
Re: Combine BAT/CMD and KIX into one file

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.


Glenn BarnasAdministrator
(KiX Supporter)
2009-03-30 02:31 PM
Re: Combine BAT/CMD and KIX into one file

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