Passing Parameters on the Command Line
Keywords: passing parameters variable substitution command line
Launching Winbatch with Parameters from Start Run Command:
You can pass parameters to WinBatch when you run the program with the following command line:
"c:\program files\winbatch\system\winbatch.exe" "c:\xxx\myfile.wbt" "\\dept-9 fred 3456"Will launch the myfile.wbt and set special internal values in myfile.wbt to:param1="\\dept-9" param2="fred" param3=3456param0 tells you how many you have. 9 parameters max:WINBATCH.EXE filename.wbt p1 p2 ... p9"filename.wbt" is any valid WBT file, and is a required parameter. "p1 p2 ... p9" are optional parameters (maximum of nine) to be passed to the WBT file on startup, delimited by spaces.
Parameters passed to a WBT file are automatically parsed into variables named: param1, param2, etc. An additional variable, param0, is the total number of command-line parameters.
To display the total number of command line parameters, use param0 as a variable in a message box.
Passing Parameters From the Command Line
If you "run" a WBT file directly, using the file association capability of Windows, it will not receive any command line parameters. In order to pass parameters to a WinBatch file, you must run the WinBatch Executable, followed by the name of the WBT file and any other desired parameters.
WBT files which are launched from the Program Manager as icons must have the complete path in the Properties dialog box in order for command line parameters to be received. The command line for "SOL.WBT" generally reads, "C:\WINBATCH\SOL.WBT". However, it is necessary to add the WinBatch executable to complete the path, so in this case it would read: "C:\WINBATCH\WINBATCH.EXE SOL.WBT".
Passing Parameters Between WBT's
To pass command line parameters from one WBT to a called WBT, place % signs around the variables (as in %variable%) when you're inside quoted strings. But watch out! Read "Important Note on Variable Substitution" below on correct way to do it in your file.
For Example:
The first WBT calls a second WBT then passes three parameters.
Call("test.wbt", "Fred Becky June")TEST.WBT contains the following line:
Message("Names are", "%param3% %param2% %param1%")Important Note on Variable Substitution:
I am trying to execute a winbatch file from a remote computer. I need to pass a filename to the program to do some processing.Example: start winbatch.exe proc.wbt 70141180.34
The problem is that once inside the program the last character of the filename is being truncated. Any ideas?
Here is a code snippet:
;proc.wbt infile = %param1% tstring = StrSub(infile,1,8) message(infile,infile) ;<=== This outputs 70141180.3 ; === instead of 70141180.34 ==Answer:
Hey, this is a real good error. Several "features" of Winbatch and your filenames are interacting and causing "interesting" results. If you remove the % signs from around param1 then it should work, i.e.infile = param1 tstring = StrSub(infile,1,8) message(infile,infile); <============= This outputs 70141180.34 ==What was happening was that because of %substitution% theinfile = %param1%line became:infile = 70141180.34So then it decided that infile must be a floating point number. But we only keep 9 digits of precision for floating point numbers, so it lost the last digit.If you just do:
infile = param1then this is a normal variable assignment, and the value held in the param1 variable is passed unmolested into the infile variableThe rule is that you do not generally need (or want) to use %substitution% EXCEPT as a quick and dirty shortcut inside quoted strings.
Article ID: W13915Filename: Passing Parameters on Command Line.txt