[Mono-osx] Cannot catch console output

Alex Soto dxdream at gmail.com
Tue Apr 17 13:48:51 UTC 2012

Hello guys, I'm trying to execute some shell commands on the Mac and do some additional stuff based on the command output but for some reason I'm not able to catch the command output from some  commands like ssh, defaults etc I'm trying to show the output to a NSTextArea but i always get a null on e.Data

But on MonoDevelop's "Application Output" window I see the result of the command executed
screenshot20120417at839.png <- this is what i would like to catch on a string

but i get null on e.Data instead the above string, here is the code I'm using 

	ProcessStartInfo ps = new ProcessStartInfo ("ssh", "");
	ps.UseShellExecute = false;
	ps.RedirectStandardOutput = true;
	using (Process p = Process.Start (ps)) 
		p.OutputDataReceived += delegate(object sender2, DataReceivedEventArgs e) 		{
				txtTexto.Value = e.Data ?? "";	
		} ;

also tried the Objective-C way, i bound NSFileHandle.h since it wasn't on MonoMac git code and I'm getting the same behavior

	NSTask task = new NSTask();
	task.LaunchPath = "/usr/bin/ssh";
	NSPipe pipe = NSPipe.pipe();
	task.StandardOutput = pipe;
	NSData data = file.ReadDataToEndOfFile();
	NSString str = NSString.FromData(data, NSStringEncoding.UTF8);
	string datos = str.ToString()
	txtTexto.Value = datos

Any ideas?? thanks in advance for any help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-osx/attachments/20120417/01d98b2c/attachment.html>

More information about the Mono-osx mailing list