我使用以下代码打开 .exe,然后我想向它传递另一个参数:
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = "cmd.exe";
StartInfo.Arguments = @"/k set inetroot=c:\depot&set corextbranch=surfacert_v2_blue_kit&c:\depot\tools\path1st\myenv.cmd";
Process.Start(StartInfo);`
Which opens up the window as below.
Now I also need to pass "sd sync dirs" which gives me some result and would like to capture the result to a variable.
为了实现这一点,我需要在
ProcessStartInfo.Arguments。
如何在上面的代码中添加第二个参数来处理 C# 代码中的所有内容。
由于它只是一个字符串,请尝试以下操作:
string[] MyArguments = { "firstarg", "secondarg"};
Process.Start("cmd.exe", String.Join(" ", MyArguments));
其中,firstarg 和 secondaryarg 是您的参数。
编辑:
哎呀忘了告诉你,如果你的参数包含空格,请执行此操作(该示例包含 1 个带空格的参数,1 个带空格的第一个参数和 1 个不带空格的第二个参数):
string[] MyArguments = { "\"first arg\"", "secondarg" };
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)