如何从c#代码向exe发送多个参数 [英] How to send multiple parameters to exe from c# code
本文介绍了如何从c#代码向exe发送多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从C#代码调用exe。如果我从命令提示符如下运行exe,它工作正常
I am trying to invoke exe from C# code . If I run the exe from command prompt like below , it works fine
C:\abc\abc.exe -e dev -l line1 -q 1
我试图通过传递所有三个参数来调用同一个exe没有参数得到传递给exe如果我在Trace中看到它。有人可以告诉我如何通过它。
I am trying to invoke the same exe by passing all three parameters but none of the parameter get pass to exe if I see it in Trace. Can someone tell me how to pass it .
以下是代码
string[] cParams = new string[] { "dev", "Line1", "1" };
ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat(exePath, "abc.exe"));
startInfo.Arguments = "\"" + cParams[0] + " " + cParams[1] + " " + cParams[2] + "\"";
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
System.Diagnostics.Process.Start(startInfo);
推荐答案
通过将它包含在引号中,一个参数。您还要退出开关( -e
, -l </ code>,
-q
)。我相信你想要的:
By enclosing it in quotes you are in effect passing only one parameter. You are also leaving out the switches (-e
, -l
, -q
). I believe you want:
ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat(exePath, "abc.exe"));
startInfo.Arguments = "-e dev -l line1 -q 1";
或者如果你的参数来自数组:
Or if your "arguments" come from the array:
startInfo.Arguments = string.Format("-e {0} -l {1} -q {2}", cParams);
这篇关于如何从c#代码向exe发送多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文