我很難在 C# 中執行 CMD 命令列(當我將命令復制到 CMD 時,它可以作業)。
命令(引號是命令的一部分):
"C:\Program Files (x86)\SolarWinds\Dameware Remote Support\dwrcc.exe" -c: -h: -m:10.10.41.82 -a:1
我是如何撰寫 C# 的:
System.Diagnostics.Process.Start("\"C:\\Program Files (x86)\\SolarWinds\\Dameware Remote Support\\dwrcc.exe\" -c: -h: -m:10.10.41.82 -a:1");
我得到的錯誤是尚未找到該位置。我認為括號或引號有問題,但我不知道是什么。
uj5u.com熱心網友回復:
嘗試用它@代替
System.Diagnostics.Process.Start(@"C:\Program Files (x86)\SolarWinds\Dameware Remote Support\dwrcc.exe", "-c: -h: -m:10.10.41.82 -a:1");
字串前綴 with@表示它應該被視為文字,即沒有轉義。
因此,例如,如果您的字串包含路徑,您通常會這樣做:
string path = "c:\\path\\to\\file.txt";
用 with@寫可以讓你寫得更清晰,不需要雙斜線
string path = @"c:\path\to\file.txt";
uj5u.com熱心網友回復:
您可以通過在十六進制值前面加上“\u”來轉義 Unicode 字符。雙引號的十六進制值為 0022,因此您可以將其包含在您的字串中。
例如:
quote = "\u0022Alive\u0022,她哭了!";
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/392606.html
