本文整理汇总了C#中ITracer.TraceProcessExitCode方法的典型用法代码示例。如果您正苦于以下问题:C# ITracer.TraceProcessExitCode方法的具体用法?C# ITracer.TraceProcessExitCode怎么用?C# ITracer.TraceProcessExitCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITracer
的用法示例。
在下文中一共展示了ITracer.TraceProcessExitCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public Tuple<string, string> Execute(ITracer tracer, Func<string, bool> onWriteOutput, Func<string, bool> onWriteError, Encoding encoding, string arguments, params object[] args)
{
using (GetProcessStep(tracer, arguments, args))
{
Process process = CreateProcess(arguments, args);
process.EnableRaisingEvents = true;
var errorBuffer = new StringBuilder();
var outputBuffer = new StringBuilder();
var idleManager = new IdleManager(IdleTimeout, tracer);
process.OutputDataReceived += (sender, e) =>
{
idleManager.UpdateActivity();
if (e.Data != null)
{
if (onWriteOutput(e.Data))
{
outputBuffer.AppendLine(Encoding.UTF8.GetString(encoding.GetBytes(e.Data)));
}
}
};
process.ErrorDataReceived += (sender, e) =>
{
idleManager.UpdateActivity();
if (e.Data != null)
{
if (onWriteError(e.Data))
{
errorBuffer.AppendLine(Encoding.UTF8.GetString(encoding.GetBytes(e.Data)));
}
}
};
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
try
{
idleManager.WaitForExit(process);
}
catch (Exception ex)
{
onWriteError(ex.Message);
throw;
}
tracer.TraceProcessExitCode(process);
string output = outputBuffer.ToString().Trim();
string error = errorBuffer.ToString().Trim();
if (process.ExitCode != 0)
{
string text = String.IsNullOrEmpty(error) ? output : error;
throw new CommandLineException(Path, process.StartInfo.Arguments, text)
{
ExitCode = process.ExitCode,
Output = output,
Error = error
};
}
return Tuple.Create(output, error);
}
}
示例2: ExecuteAsync
// This is pure async process execution
public async Task<int> ExecuteAsync(ITracer tracer, string arguments, Stream output, Stream error, Stream input = null, IdleManager idleManager = null)
{
using (GetProcessStep(tracer, arguments))
{
using (Process process = CreateProcess(arguments))
{
var wrapper = new ProcessWrapper(process);
int exitCode = await wrapper.Start(output, error, input, idleManager ?? new IdleManager(IdleTimeout, tracer));
tracer.TraceProcessExitCode(process);
return exitCode;
}
}
}