All pastes #255385 Raw Edit

Unnamed

public text v1 · immutable
#255385 ·published 2006-11-22 22:36 UTC
rendered paste body
using System;
using System.Diagnostics;
using System.Threading;

namespace process
{
	class MainClass
	{
	static Process proc;
	static AutoResetEvent signal;
	
	
		public static void Main(string[] args)
		{
		signal = new AutoResetEvent(false);
		ProcessStartInfo psi = new ProcessStartInfo();
		psi.UseShellExecute =  false;
		psi.RedirectStandardOutput = true;
		psi.FileName = "ls";
		psi.Arguments = "/usr/bin/";
		proc = Process.Start(psi);
		proc.OutputDataReceived += new DataReceivedEventHandler(get_output);
		Console.WriteLine(proc.HasExited.ToString());
		proc.BeginOutputReadLine();
		//print first line
		signal.WaitOne();
		//print second line
		signal.WaitOne();
		}
		
		public static void get_output(object sender,System.Diagnostics.DataReceivedEventArgs e)
		{
		Console.WriteLine(e.Data);
		signal.Set();
		}
		
	}
}