コード例 #1
0
ファイル: RunProcess.cs プロジェクト: JIADev/build
        public static string RunProcess(string process,
                                        string args,
                                        string workingDirectory,
                                        Dictionary <string, string> extraEnvVariables = null,
                                        int timeoutSeconds = 0,
                                        bool displayStdOut = true,
                                        bool displayStdErr = true)

        {
            var buildSystem  = new BuildSystem();
            var startInfo    = CreateStartInfo(process, args, workingDirectory);
            var outputString = new StringWriter();
            var errorBuilder = new StringWriter();

            buildSystem.GetProcess(startInfo, outputString, errorBuilder, extraEnvVariables, displayStdOut, displayStdErr);
            buildSystem.Start();

            buildSystem.WaitForExit(timeoutSeconds);

            if (buildSystem.ProcessRunning)
            {
                buildSystem.KillProcess();
                throw new TimeoutException(string.Format("Process {0} timed out after {1} seconds", startInfo.FileName, timeoutSeconds));
            }
            if (buildSystem.ExitCode != 0 || !string.IsNullOrWhiteSpace(errorBuilder.ToString()))
            {
                throw new Exception(
                          string.Format("{0} {1}: {2}{3}{4}", process, args, buildSystem.ExitCode, Environment.NewLine, errorBuilder));
            }

            return(outputString.ToString());
        }
コード例 #2
0
ファイル: RunProcess.cs プロジェクト: JIADev/build
        public static BuildSystem StartRunProcess(string process,
                                                  string args,
                                                  string workingDirectory,
                                                  Dictionary <string, string> extraEnvVariables = null,
                                                  int timeoutSeconds = 0,
                                                  bool displayStdOut = true,
                                                  bool displayStdErr = true,
                                                  ProcessTextReceivedDelegate textReceived = null)
        {
            var buildSystem = new BuildSystem();
            var startInfo   = CreateStartInfo(process, args, workingDirectory);

            buildSystem.GetProcess(startInfo, null, null, extraEnvVariables, displayStdOut, displayStdErr);
            if (textReceived != null)
            {
                buildSystem.ProcessTextReceived += textReceived;
            }
            buildSystem.Start();
            return(buildSystem);
        }