[英]Multiple arguments with cmd.exe via a C# Process
我嘗試使用C#程序中的參數調用esriRegAsm.exe。 目的是注冊一個Dll。 因此,我通常以Dll作為參數加上一些其他參數(/ p:Desktop / s)來調用esriRegAsm.exe。 如果我將其鍵入cmd.exe,則效果很好。 我以某種方式認為該進程僅將第一個字符串發送到cmd,而不是整個參數列表,但是我需要在路徑中使用“”作為空格字符。 為了進行調試,我添加了一個消息框,字符串似乎還可以。
反斜杠或雙反斜杠似乎並不重要。
string targetDir = this.Context.Parameters["targ"];
string programFilesFolder = this.Context.Parameters["proFiles"];
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C \"" + programFilesFolder + "Common Files\\\\ArcGIS\\\\bin\\\\esriRegAsm.exe\" " + "\"" + targetDir + "RArcGISTest.dll\" /p:Desktop /s";
MessageBox.Show("/C \"" + programFilesFolder + "Common Files\\\\ArcGIS\\\\bin\\\\esriRegAsm.exe\" " + "\"" + targetDir + "RArcGISTest.dll\" /p:Desktop /s");
process.StartInfo = startInfo;
process.Start();
由於我無法附加消息框的圖片,因此輸出如下:
/ C“ C:\\ Program Files(x86)\\ Common Files \\ ArcGIS \\ bin \\ esriRegAsm.exe”“ C:\\ install \\ RArcGISTest.dll” / p:台式機/ s“
為什么要雙重轉義,為什么要通過cmd.exe
路由? 只需直接執行該過程:
string targetDir = this.Context.Parameters["targ"];
string programFilesFolder = this.Context.Parameters["proFiles"];
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = Path.Combine(programFilesFolder, @"Common Files\ArcGIS\bin\esriRegAsm.exe");
startInfo.Arguments = "\"" + Path.Combine(targetDir, "RArcGISTest.dll") + "\" /p:Desktop /s";
process.StartInfo = startInfo;
process.Start();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.