2012-03-21 135 views
0

我尝试使用C#程序的参数调用esriRegAsm.exe。 目的是注册一个DLL。因此,我通常使用Dll作为参数和一些其他参数(/ p:Desktop/s)来调用esriRegAsm.exe。如果我将它输入cmd.exe,这工作正常。不知何故,我认为这个过程只发送第一个字符串到cmd而不是整个参数列表,但我需要“”作为路径中的空格字符。 为了调试,我添加了一个消息框,字符串看起来没问题。通过C#进程使用cmd.exe的多个参数

反斜杠或双反斜杠似乎不重要。

 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:\安装\ RArcGISTest.dll’/ p:桌面/ S”

+0

问题是...? – 2012-03-21 22:45:27

+0

...如何让它工作 – steffan 2012-03-21 23:08:46

回答

1

你为什么双逃避的事情,你为什么要通过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(); 
+0

适合我:)谢谢你...我逃脱了它,因为我看到了类似于targetDir字符串的东西。是的,它使用命令行很愚蠢。 – steffan 2012-03-21 23:05:41