[英]Passing a command to custom command prompt from C#
我试图从C#自定义.cmd运行命令。 问题是命令提示符准备好后,命令不会传递给提示符。 这是我的代码:
proc1.UseShellExecute = false;
string Command = @"Depanalyzer targets /n Dev\Tools\CleanupPerfCounters.exe";
proc1.FileName = @"C:\Users\xx\Desktop\MyCustom.cmd";
proc1.RedirectStandardOutput = true;
proc1.Verb = "runas";
proc1.Arguments ="/k " + Command;
p.Start();
string output = p.StandardOutput.ReadToEnd();
我看到命令窗口打开但命令没有传递给它,没有输出。
您的Command作为参数传递,该参数看起来像空格。 要使用空格传递参数,您需要将该参数包装在引号中。
proc1.UseShellExecute = false;
//wrap Command in quotes
string Command = @"""Depanalyzer targets /n Dev\Tools\CleanupPerfCounters.exe""";
proc1.FileName = @"C:\Users\xx\Desktop\MyCustom.cmd";
proc1.RedirectStandardOutput = true;
proc1.Verb = "runas";
//add quotes
proc1.Arguments ="/k " + Command;
p.Start();
string output = p.StandardOutput.ReadToEnd();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.