Pergunta

I'm trying to port a GUI application which was developed under Visual Studio C# to run under Wine on Linux. I'm having problems with the Process class. The following program works as expected when compiled with mcs and run using 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);
  }
}

But when I run it using wine (I've installed Mono for Windows under Wine), it fails with this exception:

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 

What am I doing wrong?

Foi útil?

Solução

This is due to limitations of Wine that won't be fixed.

While Windows processes running under Wine can start native processes, they cannot wait for a native process or interact with it via pipes once it is started.

There are plenty of ways around this, but they all involve some work on your part. You could, for example:

  • Use a Windows build of the programs you need to use (probably not an option, I take it).
  • Use a .sh script that executes the program you want and redirects the input/output using files.
  • Write a winelib program that acts as a proxy for the native Linux process, funneling information between the Wine and Linux pipes.
  • Use a Windows ssh client to run Linux programs on localhost.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top