Sharpen.Runtime.Exec C# (CSharp) Method

Exec() public method

public Exec ( string cmd, string envp, FilePath dir ) : SystemProcess
cmd string
envp string
dir FilePath
return SystemProcess
        public 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);
            }
        }