如何使用 process.startInfo.Arguments 传递多个参数

How to pass multiple argments with process.startInfo.Arguments

我这里有这段代码:

void Main(string[] args) {
   string[] ARRAY = new string[2];
   ARRAY[0] = "1";
   ARRAY[1] = "2";
   
   Process process = new Process();
   process.startInfo.FileName = @"PATH"; //runs itself
   process.startInfo.Arguments = ARRAY;
   process.Start();
}

我需要程序将整个数组传递给下一个实例本身(它能够接收),但我一直了解到它需要字符串。有什么解决方法吗?

process.startInfo.Argumentsstring 类型,您正试图将字符串数组传递给它。

public string Arguments { get; set; }

不是传递整个数组,而是必须先将其转换为字符串,然后将其分配给 process.startInfo.Arguments

...
process.startInfo.Arguments = string.Join(" ", ARRAY);

您的最终代码将如下所示,

void Main(string[] args) {
   string[] ARRAY = new string[2];
   ARRAY[0] = "1";
   ARRAY[1] = "2";
   
   Process process = new Process();
   process.startInfo.FileName = @"PATH"; //runs itself
   process.startInfo.Arguments = string.Join(" ", ARRAY);
   process.Start();            //^^^^^^^^^^^^^^^ This is what you need
}

更多详情:string.Join()

startInfo.Arguments = "-sk server -sky exchange -pe -n CN=localhost -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My MyAdHocTestCert.cer"