当前位置: 首页>>代码示例>>C#>>正文


C# Process.BeginErrorReadLine方法代码示例

本文整理汇总了C#中System.Diagnostics.Process.BeginErrorReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# Process.BeginErrorReadLine方法的具体用法?C# Process.BeginErrorReadLine怎么用?C# Process.BeginErrorReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.Process的用法示例。


在下文中一共展示了Process.BeginErrorReadLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Pack_Works

        public void Pack_Works()
        {
            string pathToNuGet = MakeAbsolute(@".nuget\NuGet.exe");
            string pathToNuSpec = MakeAbsolute(@"src\app\SharpRaven\SharpRaven.nuspec");

            ProcessStartInfo start = new ProcessStartInfo(pathToNuGet)
            {
                Arguments = String.Format(
                        "Pack {0} -Version {1} -Properties Configuration=Release -Properties \"ReleaseNotes=Test\"",
                        pathToNuSpec,
                        typeof(IRavenClient).Assembly.GetName().Version),
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                WindowStyle = ProcessWindowStyle.Hidden,
            };

            using (var process = new Process())
            {
                process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
                process.ErrorDataReceived += (s, e) => Console.WriteLine(e.Data);
                process.StartInfo = start;
                Assert.That(process.Start(), Is.True, "The NuGet process couldn't start.");
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                process.WaitForExit(3000);
                Assert.That(process.ExitCode, Is.EqualTo(0), "The NuGet process exited with an unexpected code.");
            }
        }
开发者ID:ehvattum,项目名称:raven-csharp,代码行数:30,代码来源:NuGetTests.cs

示例2: ExecuteSync

        public void ExecuteSync(string fileName, string arguments, string workingDirectory)
        {
            if (string.IsNullOrWhiteSpace(fileName))
                throw new ArgumentException("fileName");

            var process = new Process {
                StartInfo = {
                    FileName = fileName,
                    Arguments = arguments,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    CreateNoWindow = true,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    WorkingDirectory = workingDirectory
                },
            };

            process.OutputDataReceived += Process_OutputDataReceived;
            process.ErrorDataReceived += Process_ErrorDataReceived;
            process.Exited += Process_Exited;

            try {
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                process.WaitForExit();
            } catch (Win32Exception) {
                throw new ExecuteFileNotFoundException(fileName);
            }
        }
开发者ID:samukce,项目名称:migrate-from-svn-to-git,代码行数:32,代码来源:ProcessCaller.cs

示例3: Run

        public ProcessResult Run()
        {
            var error = new StringBuilder();
            var output = new StringBuilder();

            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    FileName = @"C:\Chocolatey\lib\NuGet.CommandLine.2.5.0\tools\Nuget.exe",
                    Arguments = "foo"
                }
            };

            process.ErrorDataReceived += (sender, args) => error.Append(args.Data);
            process.OutputDataReceived += (sender, args) => output.Append(args.Data);

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            process.WaitForExit();

            return new ProcessResult
            {
                StandardOutput = output.ToString(),
                ErrorOutput = error.ToString(),
                ExitCode = process.ExitCode
            };
        }
开发者ID:sam-io,项目名称:dotnet-playground,代码行数:34,代码来源:Console.cs

示例4: run

 public void run()
 {
     if (!File.Exists(exe)) return;
     list.Add(this);
     process = new Process();
     try
     {
         process.EnableRaisingEvents = true;
         process.Exited += new EventHandler(runFinsihed);
         process.StartInfo.FileName = Main.IsMono ? exe : wrapQuotes(exe);
         process.StartInfo.UseShellExecute = false;
         process.StartInfo.RedirectStandardOutput = true;
         process.OutputDataReceived += new DataReceivedEventHandler(OutputDataHandler);
         process.StartInfo.RedirectStandardError = true;
         process.ErrorDataReceived += new DataReceivedEventHandler(OutputDataHandler);
         process.StartInfo.Arguments = arguments;
         process.Start();
         // Start the asynchronous read of the standard output stream.
         process.BeginOutputReadLine();
         process.BeginErrorReadLine();
     }
     catch (Exception e)
     {
         Main.conn.log(e.ToString(), false, 2);
         list.Remove(this);
     }
 }
开发者ID:hohenstaufen,项目名称:Repetier-Host-for-3D-Replicator,代码行数:27,代码来源:CommandExecutioner.cs

示例5: Start

		public static void Start(string fileName, string arguments = null, string workingDirectory = null)
		{
			var startInfo =
				new ProcessStartInfo
				{
					FileName = fileName,
					Arguments = arguments,
					WorkingDirectory = workingDirectory,
					UseShellExecute = false,
					CreateNoWindow = true,
					RedirectStandardError = true,
					RedirectStandardOutput = true
				};

			using (var process = new Process { StartInfo = startInfo, EnableRaisingEvents = true })
			{
				process.ErrorDataReceived += Log;
				process.OutputDataReceived += Log;

				process.Start();
				process.BeginErrorReadLine();
				process.BeginOutputReadLine();

				process.WaitForExit();
			}
		}
开发者ID:matteomigliore,项目名称:HSDK,代码行数:26,代码来源:ProcessHelper.cs

示例6: Start

        public static AsyncProcess Start(ProcessStartInfo startInfo, IDictionary environment) {
            startInfo.RedirectStandardError = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;

            if (environment != null) {
                foreach (var i in environment.Keys) {
                    startInfo.EnvironmentVariables[(string)i] = (string)environment[i];
                }
            }

            var process = new Process {
                StartInfo = startInfo
            };

            var result = new AsyncProcess(process);

            process.EnableRaisingEvents = true;

            // set up std* access
            process.ErrorDataReceived += (sender, args) => result._stdError.Add(args.Data);
            process.OutputDataReceived += (sender, args) => result._stdOut.Add(args.Data);
            process.Exited += (sender, args) => {

                result._stdError.Completed();
                result._stdOut.Completed();
            };

            process.Start();

            process.BeginErrorReadLine();
            process.BeginOutputReadLine();

            return result;
        }
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:35,代码来源:AsyncProcess.cs

示例7: ExecuteAndCaptureOutput

        /// <summary>
        /// Executes process and capture its output.
        /// </summary>
        /// <param name="processStartInfo">The process start information.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public static Process ExecuteAndCaptureOutput(ProcessStartInfo processStartInfo, out string output)
        {
            processStartInfo.CreateNoWindow = true;
            processStartInfo.UseShellExecute = false;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardError = true;

            var process = new Process { StartInfo = processStartInfo };

            var outputBuilder = new StringBuilder();

            process.OutputDataReceived += (sender, args) =>
            {
                lock (outputBuilder)
                {
                    if (args.Data != null)
                        outputBuilder.AppendLine(args.Data);
                }
            };
            process.ErrorDataReceived += (sender, args) =>
            {
                lock (outputBuilder)
                {
                    if (args.Data != null)
                        outputBuilder.AppendLine(args.Data);
                }
            };
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();

            output = outputBuilder.ToString();
            return process;
        }
开发者ID:RainsSoft,项目名称:SharpLang,代码行数:41,代码来源:Utils.cs

示例8: OnStart

        protected override void OnStart(string[] args)
        {
            var syslog = Syslog.Build(Config.Params(), eventSource);

            process = new Process
            {
                StartInfo =
                {
                    FileName = "garden-windows.exe",
                    Arguments = "--listenNetwork=tcp -listenAddr=0.0.0.0:9241 -containerGraceTime=5m -containerizerURL=http://localhost:1788",
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    UseShellExecute = false,
                }
            };
            process.EnableRaisingEvents = true;
            process.Exited += process_Exited;

            process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
            {
                EventLog.WriteEntry(eventSource, e.Data, EventLogEntryType.Information, 0);
                if (syslog != null) syslog.Send(e.Data, SyslogSeverity.Informational);
            };
            process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
            {
                EventLog.WriteEntry(eventSource, e.Data, EventLogEntryType.Warning, 0);
                if (syslog != null) syslog.Send(e.Data, SyslogSeverity.Warning);
            };

            EventLog.WriteEntry(eventSource, "Starting", EventLogEntryType.Information, 0);
            EventLog.WriteEntry(eventSource, ("Syslog is " + (syslog==null ? "NULL" : "ALIVE")), EventLogEntryType.Information, 0);
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
        }
开发者ID:stefanschneider,项目名称:garden-windows-release,代码行数:35,代码来源:GardenWindowsService.cs

示例9: BuildSolution

        private bool BuildSolution(string solutionFilePath, string buildArguments)
        {
            var result = true;
            string output = String.Empty;
            string errorOutput = String.Empty;
            ProcessStartInfo processStartInfo = new ProcessStartInfo(net4MSBuildPath, string.Join(" ", buildArguments, solutionFilePath));
            processStartInfo.UseShellExecute = false;
            processStartInfo.ErrorDialog = false;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.RedirectStandardInput = true;
            processStartInfo.RedirectStandardOutput = true;
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.EnableRaisingEvents = true;
            process.StartInfo = processStartInfo;
            process.OutputDataReceived += (sender, args1) => output += args1.Data;
            process.ErrorDataReceived += (sender, args2) => errorOutput += args2.Data;

            bool processStarted = process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            process.WaitForExit();

            if (!String.IsNullOrEmpty(errorOutput) || !String.IsNullOrEmpty(output))
            {
                result = false;
                notificationService.Notify("Build Failed", errorOutput + Environment.NewLine + output, NotificationType.Error);
            }
            return result;
        }
开发者ID:jen20,项目名称:Jubilee,代码行数:30,代码来源:MSBuild2013.cs

示例10: LaunchCommandAsProcess

        public LaunchCommandAsProcess(string workingdirectory)
        {
            p = new Process
            {
                StartInfo =
                {
                    FileName = @"C:\Windows\System32\cmd.exe",
                    UseShellExecute = false,
                    RedirectStandardInput = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    CreateNoWindow = true
                }
            };

            if (!string.IsNullOrEmpty(workingdirectory))
                p.StartInfo.WorkingDirectory = workingdirectory;

            p.Start();

            stdIn = p.StandardInput;
            p.OutputDataReceived += Process_OutputDataReceived;
            p.ErrorDataReceived += Process_OutputDataReceived;
            p.BeginOutputReadLine();
            p.BeginErrorReadLine();
        }
开发者ID:mullvaden,项目名称:asimov-deploy-winagent,代码行数:26,代码来源:LaunchCommandAsProcess.cs

示例11: Run

        public static string Run(this ProcessStartInfo info, string logfile)
        {
            var output = new StringBuilder();
            using (var process = new Process())
            {
                process.StartInfo = info;
                process.OutputDataReceived += (sender, e) => output.AppendLine(e.Data);
                process.ErrorDataReceived += (sender, e) => output.AppendLine(e.Data);
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                process.WaitForExit();

                using (var writer = new StreamWriter(logfile, true))
                {
                    writer.WriteLine(output.ToString());
                    writer.Flush();
                }

                if (process.ExitCode != 0)
                {
                    var message = string.Format(
                        CultureInfo.InvariantCulture,
                        "The process exited with code {0}. The output was: {1}",
                        process.ExitCode.ToString(CultureInfo.InvariantCulture),
                        output.ToString());

                    throw new InvalidOperationException(message);
                }
            }

            return output.ToString();
        }
开发者ID:selony,项目名称:scriptcs,代码行数:33,代码来源:ProcessStartInfoExtensions.cs

示例12: SMTLibProcess

    public SMTLibProcess(ProcessStartInfo psi, SMTLibProverOptions options)
    {
      this.options = options;
      this.smtProcessId = smtProcessIdSeq++;

      if (options.Inspector != null) {
        this.inspector = new Inspector(options);
      }

      foreach (var arg in options.SolverArguments)
        psi.Arguments += " " + arg;

      if (cancelEvent == null && CommandLineOptions.Clo.RunningBoogieFromCommandLine) {
        cancelEvent = new ConsoleCancelEventHandler(ControlCHandler);
        Console.CancelKeyPress += cancelEvent;
      }

      if (options.Verbosity >= 1) {
        Console.WriteLine("[SMT-{0}] Starting {1} {2}", smtProcessId, psi.FileName, psi.Arguments);
      }


      try {
        prover = new Process();
        prover.StartInfo = psi;        
        prover.ErrorDataReceived += prover_ErrorDataReceived;
        prover.OutputDataReceived += prover_OutputDataReceived;
        prover.Start();
        toProver = prover.StandardInput;
        prover.BeginErrorReadLine();
        prover.BeginOutputReadLine();        
      } catch (System.ComponentModel.Win32Exception e) {
        throw new ProverException(string.Format("Unable to start the process {0}: {1}", psi.FileName, e.Message));
      }
    }
开发者ID:qunyanm,项目名称:boogie,代码行数:35,代码来源:SMTLibProcess.cs

示例13: RunExecutable

        /// <summary>
        ///   Run an executable.
        /// </summary>
        /// <param name = "executablePath">Path to the executable.</param>
        /// <param name = "arguments">The arguments to pass along.</param>
        /// <param name = "workingDirectory">The directory to use as working directory when running the executable.</param>
        /// <returns>A RunResults object which contains the output of the executable, plus runtime information.</returns>
        public static RunResults RunExecutable( string executablePath, string arguments, string workingDirectory )
        {
            RunResults runResults = new RunResults();

            if ( File.Exists( executablePath ) )
            {
                using ( Process proc = new Process() )
                {
                    proc.StartInfo.FileName = executablePath;
                    proc.StartInfo.Arguments = arguments;
                    proc.StartInfo.WorkingDirectory = workingDirectory;
                    proc.StartInfo.UseShellExecute = false;
                    proc.StartInfo.RedirectStandardOutput = true;
                    proc.StartInfo.RedirectStandardError = true;
                    proc.OutputDataReceived +=
                        ( o, e ) => runResults.Output.Append( e.Data ).Append( Environment.NewLine );
                    proc.ErrorDataReceived +=
                        ( o, e ) => runResults.ErrorOutput.Append( e.Data ).Append( Environment.NewLine );

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

                    proc.WaitForExit();
                    runResults.ExitCode = proc.ExitCode;
                }
            }
            else
            {
                throw new ArgumentException( "Invalid executable path.", "executablePath" );
            }

            return runResults;
        }
开发者ID:snakshax,项目名称:Framework-Class-Library-Extension,代码行数:41,代码来源:ProcessHelper.cs

示例14: startNzbHydraProcess

        private void startNzbHydraProcess(bool isRestart) {
            process = new Process();
            process.StartInfo.FileName = "nzbhydra.exe";
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.EnvironmentVariables["STARTEDBYTRAYHELPER"] = "true";
            //Used to auth restart and shutdown without username and password
            secretAccessKey = randomString(16);
            process.StartInfo.EnvironmentVariables["SECRETACCESSKEY"] = secretAccessKey;
            if (isRestart) {
                process.StartInfo.Arguments = "--restarted";
                writeLine("NZBHydraTray: Starting new instance of NZBHydra after a restart was requested", Color.White);
            } else {
                writeLine("NZBHydraTray: Starting new instance of NZBHydra", Color.White);
            }
            process.OutputDataReceived += OutputHandler;
            process.ErrorDataReceived += ErrorOutputHandler;
            process.EnableRaisingEvents = true;

            

            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            process.Exited += ProcessExited;
        }
开发者ID:theotherp,项目名称:NZBHydraTray,代码行数:30,代码来源:Window.cs

示例15: Run

        public static void Run(string workingDirectory, string args)
        {
            using (Process process = new Process())
            {
                process.StartInfo.WorkingDirectory = workingDirectory;
                process.StartInfo.FileName = "cmd";
                process.StartInfo.Arguments = args;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;

                process.OutputDataReceived += (sender, e) =>
                {
                    Console.WriteLine(e.Data);
                };

                process.ErrorDataReceived += (sernder, e) =>
                {
                    Console.Error.WriteLine(e.Data);
                };

                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }
        }
开发者ID:gencebay,项目名称:CloudBuilder,代码行数:26,代码来源:ProcessHelper.cs


注:本文中的System.Diagnostics.Process.BeginErrorReadLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。