[Mono-osx] Cannot catch console output
Jude DaShiell
jdashiel at shellworld.net
Wed Apr 18 00:17:00 UTC 2012
Could it be stderr is also being sent output?On Tue, 17 Apr 2012, Alex
Soto wrote:
> 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) {
> InvokeOnMainThread(()=>
> {
> txtTexto.Value = e.Data ?? "";
> });
> } ;
> p.BeginOutputReadLine();
> }
>
> 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;
> task.Launch();
> 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
>
> Alex
>
>
----------------------------------------------------------------
Jude <jdashiel-at-shellworld-dot-net>
<http://www.shellworld.net/~jdashiel/nj.html>
More information about the Mono-osx
mailing list