[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:
Dim CmdArgs() As String = {"C:\Program Files\Application\Recordings\", "Agr2", "Arg3"}
Dim arg As String = ""
For c As Integer = 0 to CmdArgs.Length - 1
arg &= """" & CmdArgs(c) & """" & " "
Next
arg = arg.Trim
Dim psi As New ProcessStartInfo
psi.Arguments = arg
psi.FileName = AppPathAndName
psi.RedirectStandardOutput = True
psi.UseShellExecute = False
Dim p As New Process
p.StartInfo = psi
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
Re: [2005] Passing multiple Commandline arguments
Try this:
Dim arg As String = CmdArgs(0) & " " & CmdArgs(1) & " " & CmdArgs(2)
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:
For c As Integer = 0 to CmdArgs.Length - 1
If CmdArgs(c).IndexOf(" ") > -1 Then
arg &= """""""""" & CmdArgs(c) & """""" & " "
Else
arg &= """" & CmdArgs(c) & """" & " "
End If
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.