Results 1 to 6 of 6

Thread: Command Line Executable - Questions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Location
    Dayton, OH USA
    Posts
    119
    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!

  2. #2
    Lively Member
    Join Date
    Sep 1999
    Location
    Liverpool, UK
    Posts
    64
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Location
    Dayton, OH USA
    Posts
    119
    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.

  4. #4
    Lively Member
    Join Date
    Sep 1999
    Location
    Liverpool, UK
    Posts
    64
    What do you mean 'output it back to the command line' ?

    You can use..
    Code:
    Shell(command)
    to run dos type commands....

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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.

  6. #6
    Addicted Member Skeen's Avatar
    Join Date
    Jul 2000
    Location
    Abingdon, Oxon
    Posts
    138

    Talking

    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.
    "It wasn't the booze that made me snooze, It was the Gin that did me in!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width