[英]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.Arguments
是string
类型,您正在尝试将字符串数组传递给它。
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 服务器 -sky exchange -pe -n CN=localhost -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss MyAdHocTestCert.cer"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.