Builder.Common.ProcessLauncher.LaunchProcess C# (CSharp) Метод

LaunchProcess() публичный Метод

public LaunchProcess ( string path, string arguments, string &writtenData ) : int
path string
arguments string
writtenData string
Результат int
        public int LaunchProcess(string path, string arguments, out string writtenData)
        {
            _receivedData = "";

            var proc = new Process();
            proc.StartInfo.FileName = path;
            proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(path);
            proc.StartInfo.Arguments = arguments;
            proc.StartInfo.CreateNoWindow = true;

            // setup output redirection
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;

            proc.OutputDataReceived += new DataReceivedEventHandler((o, e) => DataReceived(e.Data));
            proc.ErrorDataReceived += new DataReceivedEventHandler((o, e) => DataReceived(e.Data));

            proc.Start();

            proc.BeginOutputReadLine();
            proc.BeginErrorReadLine();

            proc.WaitForExit();

            writtenData = _receivedData;

            return proc.ExitCode;
        }

Usage Example

Пример #1
0
        public override void Run()
        {
            string sDirectory = ExpandMacros(m_sDirectory);

            string sCommand = "";

            switch (m_eAction)
            {
            case SVNAction.SVNRevert:
                m_oBuilder.Log("Reverting " + sDirectory + "...\r\n", true);
                sCommand = "revert -R " + sDirectory;
                break;

            case SVNAction.SVNUpdate:
                m_oBuilder.Log("Updating " + sDirectory + "...\r\n", true);
                sCommand = "update " + sDirectory;
                break;

            default:
                throw new Exception("Failed. Unknown action.");
            }

            ProcessLauncher launcher = new ProcessLauncher();

            launcher.Output += new ProcessLauncher.OutputDelegate(launcher_Output);
            string output;

            launcher.LaunchProcess(ExpandMacros(m_oBuilder.ParameterSubversionPath), ExpandMacros(sCommand), out output);

            if (output.IndexOf("svn help cleanup") > 0)
            {
                throw new Exception("Failed");
            }
        }
All Usage Examples Of Builder.Common.ProcessLauncher::LaunchProcess