-
I would like to write a command line executable with multiple switches followed by user input(see below). Found several items in this column that have helped but none give any examples of multiple switches.
Would like user to be able to do this from the command line:
filename.exe -server <name> -start <web name> -kill <package> etc...
Any examples would be greatly appreciated!
-
Can't you just strip out the different switch's from command$ ?
Build this exe and then run it with switches like this "c:\project1.exe -server MINE -start www.home.com -kill vb.exe"
Code:
'' *put this in a module
Type switch_type
name As String
value As String
End Type
Public switch_def(3) As switch_type
'' *put this in the form load or in a button
' different switches user can pass
switch_def(1).name = "-server"
switch_def(2).name = "-start"
switch_def(3).name = "-kill"
Dim switch
switch = Command$
' for each possible switch that could be passed
For x = 1 To UBound(switch_def)
' if the user has used the switch
If InStr(switch, switch_def(x).name) > 0 Then
' get the value for the current switch
switch_def(x).value = Mid$(switch, InStr(switch, switch_def(x).name) + Len(switch_def(x).name), Len(switch))
If InStr(switch_def(x).value, "-") > 0 Then switch_def(x).value = Mid$(switch_def(x).value, 1, InStr(switch_def(x).value, "-") - 1)
' remove any spaces
switch_def(x).value = Trim(switch_def(x).value)
End If
Next x
' message box for each switch
For x = 1 To UBound(switch_def)
MsgBox "Switch Values" + vbNewLine + switch_def(x).name + " = " + switch_def(x).value
Next x
-
Great example, thank you. Instead of writing output to a msgbox how would I output it back to the command line. This tool is going to be 100% command line driven.
-
What do you mean 'output it back to the command line' ?
You can use.. to run dos type commands....
-
Now how owuld you associate information in text boxes to the switches. Example lets say I had a form with text boxes that said server, start, etc. I then would want the input from the text boxes to be placed in the shell command with the exe.
-
You can set up a default command in project properties. It just means you don't have to hard code any directories in, either that or just use variables.