public static Process Start(string fileName, string arguments) { // Z:\jsc.svn\examples\java\hybrid\ubuntu\UbuntuTCPMultiplex\Program.cs //Console.WriteLine("enter Start " + new { fileName, arguments }); var x = new __Process { }; // http://stackoverflow.com/questions/19030625/redirecting-output-of-a-process-with-process-builder try { var aa = new List<string> { fileName }; aa.AddRange( // jvm wants em split arguments.Split(' ') ); //var a = new[] { fileName, arguments }; //var o = java.lang.Runtime.getRuntime().exec(aa.ToArray()); //x.InternalProcess = o; var p = new java.lang.ProcessBuilder(aa.ToArray()); var pp = p.redirectErrorStream(true); x.InternalProcess = pp.start(); // http://stackoverflow.com/questions/26174975/fire-a-cmd-exe-command-through-processbuilder-with-visual-window // can we send input? x.StandardInput = new StreamWriter( new __NetworkStream { InternalOutputStream = x.InternalProcess.getOutputStream() } ); //InputStreamExtensions.ToNetworkStream( //var sout = x.InternalProcess.getOutputStream(); var sout = new StreamReader( x.InternalProcess.getInputStream().ToNetworkStream() ); //var n = new __NetworkStream { InternalOutputStream }; //InputStreamExtensions new Thread( delegate() { try { var xx = sout.ReadLine(); while (xx != null) { Console.WriteLine(xx); xx = sout.ReadLine(); } } catch { } x.InternalConsoleReady.Set(); } ).Start(); } catch (Exception err) { Console.WriteLine(new { err.Message, err.StackTrace }); //throw err; //throw; throw new InvalidOperationException { }; } //Console.WriteLine("exit Start "); return x; }
public static Process Start(string fileName, string arguments) { // Z:\jsc.svn\examples\java\hybrid\ubuntu\UbuntuTCPMultiplex\Program.cs //Console.WriteLine("enter Start " + new { fileName, arguments }); var x = new __Process { }; // http://stackoverflow.com/questions/19030625/redirecting-output-of-a-process-with-process-builder try { var aa = new List <string> { fileName }; aa.AddRange( // jvm wants em split arguments.Split(' ') ); //var a = new[] { fileName, arguments }; //var o = java.lang.Runtime.getRuntime().exec(aa.ToArray()); //x.InternalProcess = o; var p = new java.lang.ProcessBuilder(aa.ToArray()); var pp = p.redirectErrorStream(true); x.InternalProcess = pp.start(); // http://stackoverflow.com/questions/26174975/fire-a-cmd-exe-command-through-processbuilder-with-visual-window // can we send input? x.StandardInput = new StreamWriter( new __NetworkStream { InternalOutputStream = x.InternalProcess.getOutputStream() } ); //InputStreamExtensions.ToNetworkStream( //var sout = x.InternalProcess.getOutputStream(); var sout = new StreamReader( x.InternalProcess.getInputStream().ToNetworkStream() ); //var n = new __NetworkStream { InternalOutputStream }; //InputStreamExtensions new Thread( delegate() { try { var xx = sout.ReadLine(); while (xx != null) { Console.WriteLine(xx); xx = sout.ReadLine(); } } catch { } x.InternalConsoleReady.Set(); } ).Start(); } catch (Exception err) { Console.WriteLine(new { err.Message, err.StackTrace }); //throw err; //throw; throw new InvalidOperationException { }; } //Console.WriteLine("exit Start "); return(x); }