WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Variables and Parameters

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Pass more than 9 Parameters on Command Line

Keywords:    intcontrol(1006 intcontrol (1006	255 character command line

Question:

Can I pass more than 9 parameters on the command line to Winbatch, and drag and drop them onto my compiled Winbatch EXE?

Answer:

Thanks to version 97D improvements, and the Intcontrol(1006...) function, you are not limited to 9 parameters at all!

Although in the following script, param0 reports the limited number of parameters that fit into the 255 character command line limitation, the variable paramString actually returns all of your parameters.

The following scripts displays all the parameters, and then parses them out:

paramString = IntControl(1006,0,0,0,0)
Message("Parameters: %param0%", paramstring)

paramstring=strreplace(paramstring," ",@tab)	  
paramcount=itemcount(paramstring,@tab)

If param0<>0
  For i=1 to paramcount
    param%i%= ItemExtract(i, paramstring, @tab)
  next
Endif

;Next line not needed... You can display what you've got with the following:
Askitemlist("Parameters: %paramcount%", paramstring, @tab, @unsorted, @single)

An interesting aspect to note is that while Winbatch will only send up to 9 parameters into param 1 - 9 (and will not create param10, param11, etc.), param0 is still the number of parameters, even if greater than 9, so the following statement works:
Terminate(param0 > 9,"number of parms is too many", "%param0% parameters were given")
Here's another way to parse the parameters out of the IntControl(1006...) function:
;--------------cut-------------------------

paramString = IntControl(1006,0,0,0,0)
Message("Parameters: %param0%", paramstring)
The variable ParamString can be parsed the following way:
paramString = IntControl(1006,0,0,0,0)

i = 1 ; counts words 
j = 1 ; counts parameters
While @true ; loop through paramString
par%j% = ItemExtract(i, paramString, " ") ;get a word
If StrSub(par%j%,1,1) == `"` ;if a quotation mark begins the word
While StrSub(par%j%,StrLen(par%j%),1) <> `"` ; loop until end of quotation
i = i + 1 ;goto next word
par%j% = StrCat(par%j%, " ", ItemExtract(i, paramString, " ")) ;and add word
EndWhile
par%j% = StrReplace(par%j%, `"`, ``) ;strip quotation marks from result
Endif

If j == param0 Then break ; when done parsing, break
j = j + 1 ; goto next parameter
i = i + 1 ; and next word
EndWhile
; Done
If you use param%j% instead of par%j%, the end result is to simply replace/create param10, param12, etc., as though there were no limit.

Example code from one of our users:

Below is a .ZIP file that contains a .WBT script that does this extended command line parsing. It also contains a text file that covers all of the fine nuances of command line parsing rules in WIL.

Here's a preface:

If for some reason you need more than a total of 9 parameters, refer to the attached file that contains a snippet of code that duplicates the rules used by ParseData() but handles as many parameters as your particular Windows platform will allow to fit on a single command line.

The attached file also has a text file that describes the rules used in the parsing of parameters and the usage of the different quotes and strings which contain a mix of different quoting characters.

ParseDataEx.wbt

Article ID:   W13904
Filename:   How to Pass More than 9 Parameters.txt
File Created: 2017:08:29:11:19:22
Last Updated: 2017:08:29:11:19:22