【问题标题】:C# process with arguments not working [duplicate]带有参数的C#进程不起作用[重复]
【发布时间】:2014-06-13 17:46:35
【问题描述】:
ProcessStartInfo psi = new ProcessStartInfo();
psi.CreateNoWindow = false;
psi.UseShellExecute = false;
psi.FileName = "convert.exe";
psi.WorkingDirectory = @"C:\Users\Der\Downloads\Wunderground_API_Test\Wunderground_API_Test\Wunderground_API_Test\";
psi.Arguments = " icone.gif -fuzz 10% -transparent white icone.ico";
Process.Start(psi);

如果我尝试运行此程序,则不会发生任何事情,但如果转到该路径并输入 convert.exe icone.gif -fuzz10% -transparent10% white icone.ico 它可以工作。我做错了什么?

【问题讨论】:

  • 相对于您的可执行文件,“convert.exe”在哪里?它可能只是找不到文件。你有什么例外吗?
  • convert.exe 在系统路径中
  • 您能否将输出捕获为described here 并告诉我们是否显示任何内容?
  • 显示无效参数--fuzz
  • 嗯,你的问题...

标签: c#


【解决方案1】:

我放弃了,做了一个 bat 文件,它可以工作。

        var p = new System.Diagnostics.Process();
        p.StartInfo.FileName = @"C:\Users\LL\Downloads\Wunderground_API_Test\Wunderground_API_Test\Wunderground_API_Test\icone.bat";
        p.StartInfo.WorkingDirectory = @"C:\Users\LL\Downloads\Wunderground_API_Test\Wunderground_API_Test\Wunderground_API_Test\";
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;
        p.Start();
        p.WaitForExit();

【讨论】:

    【解决方案2】:

    这是因为 C# 将 StartInfo 参数作为 Unicode 传递,而您的程序 "convert.exe" 不处理 Unicode 参数的解释。当你通过批处理文件调用它时,它不会将参数作为 Unicode 传递。

    以下链接似乎解决了您的问题。带有代码示例。

    Application started by Process.Start() isn't getting arguments

    【讨论】:

      【解决方案3】:

      所以,在我的机器上的 LINQPad 上尝试这个,我认为这可能是对工作目录的误解。工作目录不是文件的位置,它是文件应该认为它正在运行的位置。尝试删除该行并在 FileName 中指定完整路径。这对我有用。

      【讨论】:

      • OP得到的错误来自Converts a FAT volume to NTFS.....的windows convert.exe工具。
      猜你喜欢
      • 1970-01-01
      • 2016-03-17
      • 2023-03-23
      • 1970-01-01
      • 2015-03-09
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多