简体   繁体   中英

Passing multiple arguments as command line args

I am calling one .NET app from another using Process.Start and passing in a bunch of strings as command line arguments:

startInfo.Arguments = String.Join("""  """, MyArray)
Dim p As Process = Process.Start(startInfo)

My intent is to pass in something like:

"first value" "second value" "third value"

and retrieve from within the second app:

Sub Main(ByVal args() as String)
    If args.Length > 0 Then

    End If
    ...
End Sub

Unfortunately args.Length only returns 1 - all the values I pass get passed on as a single value: "first value second value third value"

I tried wrapping each in double quotes in the first app but does not seem to help. I know I can just retrieve args(0) and then split it into an array of values but I do not want to do that. Also somehow it worked for me before, even without double quotes. So I am trying to figure out what happened and how can I make it pass my strings as multiple values instead of 1.

Your String.Join is not going to give you what you want. It will not put the double quote at the start and end of the string.

startInfo.Arguments = """" + String.Join(""" """, MyArray) + """"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM