1

我正在尝试移植一个在 Visual Studio C# 下开发的 GUI 应用程序,以便在 Linux 上的 Wine 下运行。我遇到了 Process 类的问题。以下程序在使用 mcs 编译并使用 mono 运行时按预期工作:

using System.Diagnostics;
using System;

class TestProcess {
  static void Main() {
    Process process = new Process();
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.FileName = "/usr/bin/find";
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.Arguments = "/sys";

    process.ErrorDataReceived += new DataReceivedEventHandler(output);
    process.OutputDataReceived += new DataReceivedEventHandler(output);

    process.Start();
    process.BeginErrorReadLine();
    process.BeginOutputReadLine();
    process.WaitForExit();
  }

  static void output(object sender, DataReceivedEventArgs e) {
    Console.WriteLine(e.Data);
  }
}

但是当我使用 wine 运行它时(我已经在 Wine 下安装了 Mono for Windows),它会失败并出现以下异常:

Unhandled Exception: System.InvalidOperationException: Standard error has not been redirected or process has not been started.
  at System.Diagnostics.Process.BeginErrorReadLine () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:BeginErrorReadLine ()
  at TestProcess.Main () [0x00000] in <filename unknown>:0 

我究竟做错了什么?

4

1 回答 1

2

这是由于 Wine 的限制无法修复。

虽然在 Wine 下运行的 Windows 进程可以启动本机进程,但一旦启动,它们就不能等待本机进程或通过管道与其交互。

有很多方法可以解决这个问题,但它们都涉及到你的一些工作。例如,您可以:

  • 使用您需要使用的程序的 Windows 版本(可能不是一个选项,我接受它)。
  • 使用 .sh 脚本执行您想要的程序并使用文件重定向输入/输出。
  • 编写一个 winelib 程序,作为本机 Linux 进程的代理,在 Wine 和 Linux 管道之间汇集信息。
  • 使用 Windows ssh 客户端在 localhost 上运行 Linux 程序。
于 2012-11-15T20:13:15.867 回答