【问题标题】:System.ComponentModel.Win32Exception: 'The system cannot find the file specified'System.ComponentModel.Win32Exception: '系统找不到指定的文件'
【发布时间】:2019-03-01 01:35:55
【问题描述】:

相同的代码在 Windows 10 中有效,但在 Windows Server 2012 R2 中无效。

        ProcessStartInfo start = new ProcessStartInfo();

        start.FileName = "java";
        start.UseShellExecute = false;
        start.CreateNoWindow = true;
        start.RedirectStandardOutput = true;
        start.RedirectStandardError = true;

        start.Arguments = @"-jar avro-tools-1.8.2.jar tojson input.avro";

        using (Process process = Process.Start(start))
        //in above line is where the error appears.

我检查了路径,没问题。我从命令行运行它并且正在工作。不知道还要检查什么。

【问题讨论】:

  • 你试过UseShellExecute = true吗?
  • 你试过“java.exe”还是完整路径?
  • @DanielA.White,我想我不能使用它。 System.InvalidOperationException: 'Process 对象必须将 UseShellExecute 属性设置为 false 才能重定向 IO 流。'
  • @Max 我尝试了 java.exe 完整路径,得到了相同的结果,我认为这也行不通,因为 .jar 和 .avro 文件与 java 不在同一位置。只是为了在控制台中澄清是有效的。
  • 这很奇怪。我刚刚在 Windows 2012 R2 (6.3.9600) 上编译并运行了您的代码。它工作得很好。 Windows 不会检查 jar/avro 文件的路径——它们只是传递给 Java 的字符串——java 会抛出错误,但 Java 必须开始检查。

标签: c#


【解决方案1】:

最后的解决方案是添加一个新的配置文件作为 x64 并使用它运行调试器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多