简体   繁体   English

将多个参数作为命令行参数传递

[英]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: 我正在使用Process.Start从另一个调用一个.NET应用程序,并将一串字符串作为命令行参数传递:

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" 不幸的是args.Length仅返回1-我传递的所有值都作为单个值传递:“第一个值第二个值第三个值”

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. 我知道我可以检索args(0),然后将其拆分为值数组,但我不想这样做。 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. 所以我想弄清楚发生了什么,如何使它以多个值而不是1的形式传递我的字符串。

Your String.Join is not going to give you what you want. 您的String.Join不会给您您想要的。 It will not put the double quote at the start and end of the string. 不会将双引号放在字符串的开头和结尾。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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