[Mono-list] Process.StandardOutput.Readline() hangs on Mono but not on .NET

jrjr jresnick at gmail.com
Mon Feb 4 22:41:41 UTC 2013


Hi,

I'm trying to port a program from .NET/windows to Mono/linux, but I'm
running into some trouble with the System.Diagnostics.Process class.  The
program uses the Process class to invoke a python script, send data to its
stdin, and read data back from its stdout.  The mechanism is shown in the
following code:

	class Program
	{
		static void Main(string[] args)
		{
			var startInfo = new ProcessStartInfo("python");
			startInfo.Arguments = "./hello.py";
			startInfo.UseShellExecute = false;
			startInfo.RedirectStandardInput = true;
			startInfo.RedirectStandardOutput = true;

			var p = Process.Start(startInfo);
			if (p.HasExited) // verify it actually started
				return;

			var names = new[] { "Bobby", "Billy", "Jenny", "June" };
			foreach (var name in names)
			{
				p.StandardInput.WriteLine(name);

				var result = p.StandardOutput.ReadLine();
				Console.WriteLine("Result: {0}", result);
			}

			p.Kill();
		}
	}

and the python script is this:

#!/usr/bin/python
line = raw_input()
while len(line) > 0:
    print("Hello " + line)
    line = raw_input()

This all works fine on .NET/Windows but on Mono/Linux it hangs on the call
to p.StandardOutput.ReadLine(). Any idea what's going on here? I don't have
much experience with Linux.

ps. I also tried changing the python script to use sys.stdin and sys.stdout
instead of raw_input and print, but this made no difference.



--
View this message in context: http://mono.1490590.n4.nabble.com/Process-StandardOutput-Readline-hangs-on-Mono-but-not-on-NET-tp4658454.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list