Results 1 to 3 of 3

Thread: [2005] Passing multiple Commandline arguments

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    [2005] Passing multiple Commandline arguments

    I am trying to pass multiple command line arguments to an application. The problem is that some of the arguments have spaces in them. I seem to be only able to send it as one argument, or seporated on the spaces.

    So here is a simplified version of what I am doing.
    VB Code:
    1. Dim CmdArgs() As String = {"C:\Program Files\Application\Recordings\", "Agr2", "Arg3"}
    2.  
    3. Dim arg As String = ""
    4.  
    5. For c As Integer = 0 to CmdArgs.Length - 1
    6.    arg &= """" & CmdArgs(c) & """" & " "
    7. Next
    8.  
    9. arg = arg.Trim
    10.  
    11. Dim psi As New ProcessStartInfo
    12. psi.Arguments = arg
    13. psi.FileName = AppPathAndName
    14. psi.RedirectStandardOutput = True
    15. psi.UseShellExecute = False
    16.  
    17. Dim p As New Process
    18. p.StartInfo = psi
    19. p.Start()

    The way the code is above the argument string looks like this
    "C:\Program Files\Application\Recordings\" "Arg2" "Arg3"
    This only passes 1 argument that looks like this:
    C:\Program Files\Application\Recordings\" Arg2 Arg3

    If I add quotes a quote to the begining and end of arg this is what it looks like
    ""C:\Program Files\Application\Recordings\" "Arg2" "Arg3""
    This passes 4 arguments:
    C:\Program
    Files\Application\Recordings\"
    Arg2
    Arg3"

    notice the " in red
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Passing multiple Commandline arguments

    Try this:
    Dim arg As String = CmdArgs(0) & " " & CmdArgs(1) & " " & CmdArgs(2)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] Passing multiple Commandline arguments

    Tried that. It splits on spaces then.

    I think I got it though.

    I changed the for loop above to this
    VB Code:
    1. For c As Integer = 0 to CmdArgs.Length - 1
    2.    If CmdArgs(c).IndexOf(" ") > -1 Then
    3.        arg &= """""""""" & CmdArgs(c) & """""" & " "
    4.    Else
    5.        arg &= """" & CmdArgs(c) & """" & " "
    6.    End If
    7. Next

    What I don't like about this method is that if the argument has spaces it is passed with quotes around it. I would really prefer not to have that. But I can't get it to work any other way.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

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