簡體   English   中英

將命令傳遞給C#的自定義命令提示符

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM