本文整理汇总了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.");
}
}
示例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);
}
}
示例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
};
}
示例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);
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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));
}
}
示例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;
}
示例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;
}
示例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();
}
}