【问题标题】:Multiple arguments with cmd.exe via a C# Process通过 C# 进程使用 cmd.exe 的多个参数
【发布时间】:2012-03-21 22:42:33
【问题描述】:

我尝试使用来自 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:Desktop /s"

【问题讨论】:

  • 问题是......?

标签: c# process cmd esri


【解决方案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();

【讨论】:

  • 为我工作 :) 谢谢...我双重转义它,因为我看到 targetDir 字符串有类似的东西。是的,使用命令行很愚蠢。
猜你喜欢
  • 1970-01-01
  • 2017-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-05
  • 2018-11-07
  • 1970-01-01
  • 2023-03-21
相关资源
最近更新 更多