internal SystemProcess Exec(string[] cmd, string[] envp, FilePath dir) { try { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = cmd[0]; psi.Arguments = string.Join(" ", cmd, 1, cmd.Length - 1); if (dir != null) { psi.WorkingDirectory = dir.GetPath(); } psi.UseShellExecute = false; psi.RedirectStandardInput = true; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.CreateNoWindow = true; if (envp != null) { foreach (string str in envp) { int index = str.IndexOf('='); psi.EnvironmentVariables[str.Substring(0, index)] = str.Substring(index + 1); } } return(SystemProcess.Start(psi)); } catch (System.ComponentModel.Win32Exception ex) { throw new IOException(ex.Message); } }
public static SystemProcess Start(this ProcessStartInfo si) { si.UseShellExecute = false; si.RedirectStandardInput = true; si.RedirectStandardError = true; si.RedirectStandardOutput = true; si.CreateNoWindow = true; return(SystemProcess.Start(si)); }