static int DoCompilation(string outstr, string working_dir, Dictionary <string, string> env_vars, List <string> gac_roots, ref string output, ref string error, IProgressMonitor monitor) { output = Path.GetTempFileName(); error = Path.GetTempFileName(); StreamWriter outwr = new StreamWriter(output); StreamWriter errwr = new StreamWriter(error); // the default should be valid, string luac = PropertyService.Get <string>("Lua.DefaultInterpreterPath"); if (string.IsNullOrEmpty(luac)) { monitor.ReportError("Can't find Lua compiler (please set the default interpreter path)", new Exception()); return(1); } luac += "c"; ProcessStartInfo pinfo = new ProcessStartInfo(luac, outstr); pinfo.WorkingDirectory = working_dir; if (gac_roots.Count > 0) { // Create the gac prefix string string gacPrefix = string.Join("" + Path.PathSeparator, gac_roots.ToArray()); string oldGacVar = Environment.GetEnvironmentVariable("MONO_GAC_PREFIX"); if (!string.IsNullOrEmpty(oldGacVar)) { gacPrefix += Path.PathSeparator + oldGacVar; } pinfo.EnvironmentVariables ["MONO_GAC_PREFIX"] = gacPrefix; } foreach (KeyValuePair <string, string> kv in env_vars) { pinfo.EnvironmentVariables.Add(kv.Key, kv.Value); } pinfo.UseShellExecute = false; pinfo.RedirectStandardOutput = true; pinfo.RedirectStandardError = true; MonoDevelop.Core.Execution.ProcessWrapper pw = Runtime.ProcessService.StartProcess(pinfo, outwr, errwr, null); pw.WaitForOutput(); int exitCode = pw.ExitCode; outwr.Close(); errwr.Close(); pw.Dispose(); return(exitCode); }
static int DoCompilation(IProgressMonitor monitor, string compilerName, string compilerArgs, string working_dir, ExecutionEnvironment envVars, List <string> gacRoots, ref string output, ref string error) { output = Path.GetTempFileName(); error = Path.GetTempFileName(); StreamWriter outwr = new StreamWriter(output); StreamWriter errwr = new StreamWriter(error); ProcessStartInfo pinfo = new ProcessStartInfo(compilerName, compilerArgs); pinfo.StandardErrorEncoding = Encoding.UTF8; pinfo.StandardOutputEncoding = Encoding.UTF8; // The "." is a workaround for a bug in ProcessStartInfo.WorkingDirectory - not able to handle null pinfo.WorkingDirectory = working_dir ?? "."; if (gacRoots.Count > 0) { // Create the gac prefix string string gacPrefix = string.Join("" + Path.PathSeparator, gacRoots.ToArray()); string oldGacVar = Environment.GetEnvironmentVariable("MONO_GAC_PREFIX"); if (!string.IsNullOrEmpty(oldGacVar)) { gacPrefix += Path.PathSeparator + oldGacVar; } pinfo.EnvironmentVariables ["MONO_GAC_PREFIX"] = gacPrefix; } envVars.MergeTo(pinfo); pinfo.UseShellExecute = false; pinfo.RedirectStandardOutput = true; pinfo.RedirectStandardError = true; MonoDevelop.Core.Execution.ProcessWrapper pw = Runtime.ProcessService.StartProcess(pinfo, outwr, errwr, null); using (var mon = new AggregatedOperationMonitor(monitor, pw)) { pw.WaitForOutput(); } int exitCode = pw.ExitCode; bool cancelRequested = pw.CancelRequested; outwr.Close(); errwr.Close(); pw.Dispose(); return(cancelRequested ? 0 : exitCode); }
static int DoCompilation(string outstr, string working_dir, ExecutionEnvironment envVars, List <string> gacRoots, ref string output, ref string error) { output = Path.GetTempFileName(); error = Path.GetTempFileName(); StreamWriter outwr = new StreamWriter(output); StreamWriter errwr = new StreamWriter(error); string[] tokens = outstr.Split(' '); outstr = outstr.Substring(tokens[0].Length + 1); ProcessStartInfo pinfo = new ProcessStartInfo(tokens[0], outstr); pinfo.WorkingDirectory = working_dir; if (gacRoots.Count > 0) { // Create the gac prefix string string gacPrefix = string.Join("" + Path.PathSeparator, gacRoots.ToArray()); string oldGacVar = Environment.GetEnvironmentVariable("MONO_GAC_PREFIX"); if (!string.IsNullOrEmpty(oldGacVar)) { gacPrefix += Path.PathSeparator + oldGacVar; } pinfo.EnvironmentVariables ["MONO_GAC_PREFIX"] = gacPrefix; } envVars.MergeTo(pinfo); pinfo.UseShellExecute = false; pinfo.RedirectStandardOutput = true; pinfo.RedirectStandardError = true; MonoDevelop.Core.Execution.ProcessWrapper pw = Runtime.ProcessService.StartProcess(pinfo, outwr, errwr, null); pw.WaitForOutput(); int exitCode = pw.ExitCode; outwr.Close(); errwr.Close(); pw.Dispose(); return(exitCode); }
private static int DoCompilation(string cmd, string args, string wd, IProgressMonitor monitor, ref string error) { int exitcode = 0; error = Path.GetTempFileName(); StreamWriter errwr = new StreamWriter(error); ProcessStartInfo pinfo = new ProcessStartInfo(cmd, args); pinfo.UseShellExecute = false; pinfo.RedirectStandardOutput = true; pinfo.RedirectStandardError = true; pinfo.WorkingDirectory = wd; using (MonoDevelop.Core.Execution.ProcessWrapper pw = Runtime.ProcessService.StartProcess(pinfo, monitor.Log, errwr, null)) { pw.WaitForOutput(); exitcode = pw.ExitCode; } errwr.Close(); return(exitcode); }
public override IProcessAsyncOperation StartConsoleProcess (string command, string arguments, string workingDirectory, IDictionary<string, string> environmentVariables, string title, bool pauseWhenFinished) { ProbeTerminal (); string exec = runner (command, arguments, workingDirectory, title, pauseWhenFinished); var psi = new ProcessStartInfo (terminal_command, exec) { CreateNoWindow = true, UseShellExecute = false, }; foreach (var env in environmentVariables) psi.EnvironmentVariables [env.Key] = env.Value; ProcessWrapper proc = new ProcessWrapper (); proc.StartInfo = psi; proc.Start (); return proc; }
public override IProcessAsyncOperation StartConsoleProcess (string command, string arguments, string workingDirectory, IDictionary<string, string> environmentVariables, string title, bool pauseWhenFinished) { string args = "/C \"title " + title + " && \"" + command + "\" " + arguments; if (pauseWhenFinished) args += " & pause\""; else args += "\""; var psi = new ProcessStartInfo ("cmd.exe", args) { CreateNoWindow = false, WorkingDirectory = workingDirectory, UseShellExecute = false, }; foreach (var env in environmentVariables) psi.EnvironmentVariables [env.Key] = env.Value; ProcessWrapper proc = new ProcessWrapper (); proc.StartInfo = psi; proc.Start (); return proc; }
public override ProcessAsyncOperation StartConsoleProcess ( string command, string arguments, string workingDirectory, IDictionary<string, string> environmentVariables, string title, bool pauseWhenFinished) { var proc = new ProcessWrapper { StartInfo = CreateConsoleStartInfo ( command, arguments, workingDirectory, environmentVariables, title, pauseWhenFinished ) }; proc.Start (); return proc.ProcessAsyncOperation; }
void Connect () { log.WriteConsoleLogText ("Connecting...\n"); var mtouch = "/Developer/MonoTouch/usr/bin/mtouch"; var psi = new ProcessStartInfo (mtouch, "-logdev") { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; process = Runtime.ProcessService.StartProcess (psi, OnProcessOutput, OnProcessError, delegate { Disconnect (); }); process.EnableRaisingEvents = true; }
void Disconnect () { if (process == null) return; log.WriteConsoleLogText ("\nDisconnected\n"); if (!process.HasExited) process.Kill (); else if (process.ExitCode != 0) log.WriteError (string.Format ("Unknown error {0}\n", process.ExitCode)); process.Dispose (); process = null; }
void ShowHelpExternal (string topic) { try { if (pw == null || pw.HasExited == true) { outWriter = new StringWriter (); errWriter = new StringWriter (); pw = Runtime.ProcessService.StartProcess ( "monodoc", "--remote-mode" + DirArgs, "", outWriter, errWriter, delegate { if (pw.ExitCode == 0) return; MessageService.ShowError ( String.Format ( "MonoDoc exited with a exit code = {0}.", pw.ExitCode, errWriter.ToString ())); pw = null; }, true); } if (pw != null && !pw.HasExited) { pw.StandardInput.WriteLine (topic); Console.WriteLine (outWriter.ToString ()); Console.WriteLine (errWriter.ToString ()); } } catch (Exception e) { MessageService.ShowException (e); useExternalMonodoc = false; } }
void CheckExternalMonodoc () { firstCall = false; try { outWriter = new StringWriter (); errWriter = new StringWriter (); pw = Runtime.ProcessService.StartProcess ( "monodoc", "--help", "", outWriter, errWriter, delegate { if (pw.ExitCode != 0) MessageService.ShowError ( String.Format ( "MonoDoc exited with a exit code = {0}. Error : {1}", pw.ExitCode, errWriter.ToString ())); pw = null; }, true); pw.WaitForOutput (); if (outWriter.ToString ().IndexOf ("--about") > 0) useExternalMonodoc = true; pw = null; } catch (Exception e) { MessageService.ShowError (String.Format ( "Could not start monodoc : {0}", e.ToString ())); } if (!useExternalMonodoc) MessageService.ShowError ( GettextCatalog.GetString ("You need a newer monodoc to use it externally from monodevelop. Using the integrated help viewer now.")); }
public ProcessWrapper StartProcess (ProcessStartInfo startInfo, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited) { if (startInfo == null) throw new ArgumentException ("startInfo"); ProcessWrapper p = new ProcessWrapper(); if (outputStreamChanged != null) { startInfo.RedirectStandardOutput = true; p.OutputStreamChanged += outputStreamChanged; } if (errorStreamChanged != null) { startInfo.RedirectStandardError = true; p.ErrorStreamChanged += errorStreamChanged; } startInfo.CreateNoWindow = true; p.StartInfo = startInfo; ProcessEnvironmentVariableOverrides (p.StartInfo); // FIXME: the bug is long gone, but removing the hacks in ProcessWrapper w/o bugs will be tricky // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process" // Process leaks when an exit event is registered // instead we use another thread to monitor I/O and wait for exit // if (exited != null) // p.Exited += exited; // p.EnableRaisingEvents = true; if (exited != null) { MonoDevelop.Core.OperationHandler handler = null; handler = delegate (MonoDevelop.Core.IAsyncOperation op) { op.Completed -= handler; exited (p, EventArgs.Empty); }; ((MonoDevelop.Core.IAsyncOperation)p).Completed += handler; } Counters.ProcessesStarted++; p.Start (); return p; }
protected static string GeneratePkgConfigArgs (ProjectPackageCollection packages, string pkgConfigArg) { if (packages == null || packages.Count < 1) return string.Empty; string originalPkgConfigPath = Environment.GetEnvironmentVariable ("PKG_CONFIG_PATH"); string pkgConfigPath = originalPkgConfigPath; StringBuilder libs = new StringBuilder (); foreach (Package p in packages) { if (Path.IsPathRooted (p.File)) { pkgConfigPath = string.Format ("{0}{1}{2}", pkgConfigPath, Path.PathSeparator, Path.GetDirectoryName (p.File)); libs.Append (Path.GetFileNameWithoutExtension (p.File) + " "); } else { libs.Append (p.File + " "); } } string args = string.Format ("{0} \"{1}\"", pkgConfigArg, libs.ToString ().Trim ()); StringWriter output = new StringWriter (); ProcessWrapper proc = new ProcessWrapper (); try { Environment.SetEnvironmentVariable ("PKG_CONFIG_PATH", pkgConfigPath); proc = Runtime.ProcessService.StartProcess ("pkg-config", args, null, null); proc.WaitForExit (); string line; while ((line = proc.StandardOutput.ReadLine ()) != null) output.WriteLine (line); } catch (Exception ex) { MessageService.ShowError ("You need to have pkg-config installed"); } finally { proc.Close (); Environment.SetEnvironmentVariable ("PKG_CONFIG_PATH", originalPkgConfigPath); } return output.ToString (); }
public ProcessAsyncOperation StartConsoleProcess(string command, string arguments, string workingDirectory, OperationConsole console, IDictionary <string, string> environmentVariables = null, EventHandler exited = null) { var externalConsole = console as ExternalConsole; if ((console == null || externalConsole != null) && externalConsoleHandler != null) { var dict = new Dictionary <string, string> (); if (environmentVariables != null) { foreach (var kvp in environmentVariables) { dict[kvp.Key] = kvp.Value; } } if (environmentVariableOverrides != null) { foreach (var kvp in environmentVariableOverrides) { dict[kvp.Key] = kvp.Value; } } var p = externalConsoleHandler(command, arguments, workingDirectory, dict, externalConsole?.Title ?? GettextCatalog.GetString("{0} External Console", BrandingService.ApplicationName), externalConsole != null ? !externalConsole.CloseOnDispose : false); if (p != null) { if (exited != null) { p.Task.ContinueWith(t => exited(p, EventArgs.Empty), Runtime.MainTaskScheduler); } Counters.ProcessesStarted++; return(p); } else { LoggingService.LogError("Could not create external console for command: " + command + " " + arguments); } } ProcessStartInfo psi = CreateProcessStartInfo(command, arguments, workingDirectory, false); if (environmentVariables != null) { foreach (KeyValuePair <string, string> kvp in environmentVariables) { psi.EnvironmentVariables [kvp.Key] = kvp.Value; } } try { ProcessWrapper pw = StartProcess(psi, console.Out, console.Error, null); new ProcessMonitor(console, pw.ProcessAsyncOperation, exited); return(pw.ProcessAsyncOperation); } catch (Exception ex) { // If the process can't be started, dispose the console now since ProcessMonitor won't do it console.Error.WriteLine(GettextCatalog.GetString("The application could not be started")); LoggingService.LogError("Could not start process for command: " + psi.FileName + " " + psi.Arguments, ex); console.Dispose(); return(NullProcessAsyncOperation.Failure); } }
void Connect () { log.Clear (); log.WriteConsoleLogText ("Connecting...\n"); process = MonoDroidFramework.Toolbox.LogCat (Device, OnProcessOutput, OnProcessError); process.Exited += delegate { Disconnect (); }; process.EnableRaisingEvents = true; }
void ShowHelpExternal (string topic) { try { if (pw == null || pw.HasExited == true) { outWriter = new StringWriter (); errWriter = new StringWriter (); pw = Runtime.ProcessService.StartProcess ( "monodoc", "--remote-mode" + DirArgs, "", outWriter, errWriter, delegate { if (pw.ExitCode == 0) return; MessageService.ShowError ( $"MonoDoc exited with exit code {pw.ExitCode}{Environment.NewLine}{errWriter.ToString()}." ); pw = null; }, true); } if (pw != null && !pw.HasExited) { pw.StandardInput.WriteLine (topic); Console.WriteLine (outWriter.ToString ()); Console.WriteLine (errWriter.ToString ()); } } catch (Exception e) { MessageService.ShowError (GettextCatalog.GetString ("Help Viewer could not be opened"), e); useExternalMonodoc = false; } }
protected string GeneratePkgLinkerArgs (ProjectPackageCollection packages) { if (packages == null || packages.Count < 1) return string.Empty; StringBuilder libs = new StringBuilder (); foreach (ProjectPackage p in packages) libs.Append (p.File + " "); string args = string.Format ("--libs {0}", libs.ToString ().Trim ()); StringWriter output = new StringWriter (); ProcessWrapper proc = new ProcessWrapper (); try { proc = Runtime.ProcessService.StartProcess ("pkg-config", args, null, null); proc.WaitForExit (); string line; while ((line = proc.StandardOutput.ReadLine ()) != null) output.WriteLine (line); } catch (Exception ex) { IdeApp.Services.MessageService.ShowError (ex, "You need to have pkg-config installed"); } finally { proc.Close (); } return output.ToString (); }
void Dispose (bool disposing) { if (mtouchProcess == null) return; if (disposing) { mtouchProcess.Dispose (); outTail.Dispose (); errTail.Dispose (); mtouchProcess = null; } }
public IPhoneProcess (ProcessWrapper mtouchProcess, Tail outTail, Tail errTail) { this.mtouchProcess = mtouchProcess; this.outTail = outTail; this.errTail = errTail; }
public ProcessWrapper StartProcess (ProcessStartInfo startInfo, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited) { if (startInfo == null) throw new ArgumentException ("startInfo"); ProcessWrapper p = new ProcessWrapper(); if (outputStreamChanged != null) { startInfo.RedirectStandardOutput = true; p.OutputStreamChanged += outputStreamChanged; } if (errorStreamChanged != null) { startInfo.RedirectStandardError = true; p.ErrorStreamChanged += errorStreamChanged; } startInfo.CreateNoWindow = true; p.StartInfo = startInfo; ProcessEnvironmentVariableOverrides (p.StartInfo); // FIXME: the bug is long gone, but removing the hacks in ProcessWrapper w/o bugs will be tricky // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process" // Process leaks when an exit event is registered // instead we use another thread to monitor I/O and wait for exit // if (exited != null) // p.Exited += exited; // p.EnableRaisingEvents = true; Counters.ProcessesStarted++; p.Start (); if (exited != null) p.Task.ContinueWith (t => exited (p, EventArgs.Empty), Runtime.MainTaskScheduler); return p; }