/// <summary>A straightforward constructor.</summary> private RunningProcess(WebServiceAnnotator _enclosing, Process process) { this._enclosing = _enclosing; this.process = process; TextWriter errWriter = new BufferedWriter(new OutputStreamWriter(System.Console.Error)); this.stderr = new StreamGobbler(process.GetErrorStream(), errWriter); this.stderr.Start(); TextWriter outWriter = new BufferedWriter(new OutputStreamWriter(System.Console.Out)); this.stdout = new StreamGobbler(process.GetErrorStream(), outWriter); this.stdout.Start(); this.shutdownHoook = new Thread(null); Runtime.GetRuntime().AddShutdownHook(this.shutdownHoook); }
/// <exception cref="System.IO.IOException"/> public BZip2PipedOutputStream(string filename, OutputStream err) { string bzip2 = Runtime.GetProperty("bzip2", "bzip2"); string cmd = bzip2; // + " > " + filename; //log.info("getBZip2PipedOutputStream: Running command: "+cmd); ProcessBuilder pb = new ProcessBuilder(); pb.Command(cmd); this.process = pb.Start(); this.filename = filename; OutputStream outStream = new FileOutputStream(filename); errWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(err))); outGobbler = new ByteStreamGobbler("Output stream gobbler: " + cmd + " " + filename, process.GetInputStream(), outStream); errGobbler = new StreamGobbler(process.GetErrorStream(), errWriter); outGobbler.Start(); errGobbler.Start(); }
private int ExecProcess(IList<string> cmds, FFMpegCallbacks sc) { //ensure that the arguments are in the correct Locale format // TODO: Useless since SOX is called internally. Remove. for ( int i = 0; i < cmds.Count; i++) { cmds[i] = string.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US"), "%s", cmds[i]); } ProcessBuilder pb = new ProcessBuilder(cmds); pb.Directory(fileBinDir); var cmdlog = new Java.Lang.StringBuilder(); foreach (string cmd in cmds) { cmdlog.Append(cmd); cmdlog.Append(' '); } sc.ShellOut(cmdlog.ToString()); pb.RedirectErrorStream(true); var process = pb.Start(); StreamGobbler errorGobbler = new StreamGobbler(this, process.ErrorStream, "ERROR", sc); StreamGobbler outputGobbler = new StreamGobbler(this, process.InputStream, "OUTPUT", sc); errorGobbler.Run(); outputGobbler.Run(); int exitVal = process.WaitFor(); while (outputGobbler.IsAlive || errorGobbler.IsAlive); sc.ProcessComplete(exitVal); return exitVal; }