我正在尝试移植在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
我做错了什么?
答案 0 :(得分:1)
这是由于葡萄酒的局限性无法修复。
虽然在Wine下运行的Windows进程可以启动本机进程,但是一旦启动它们就不能等待本机进程或通过管道与它进行交互。
这方面有很多方法,但它们都涉及到你的一些工作。你可以,例如: