本文整理汇总了C#中System.Diagnostics.Process.BeginOutputReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# Process.BeginOutputReadLine方法的具体用法?C# Process.BeginOutputReadLine怎么用?C# Process.BeginOutputReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.BeginOutputReadLine方法的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: ConvertFile
public virtual string ConvertFile(Episode episode, ProgressNotification notification)
{
_notification = notification;
_currentEpisode = episode;
var outputFile = _configProvider.GetValue("iPodConvertDir", "");
var handBrakePreset = _configProvider.GetValue("HandBrakePreset", "iPhone & iPod Touch");
var handBrakeCommand = String.Format("-i \"{0}\" -o \"{1}\" --preset=\"{2}\"", episode.EpisodeFile.Path, outputFile, handBrakePreset);
var handBrakeFile = @"C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe";
try
{
var process = new Process();
process.StartInfo.FileName = handBrakeFile;
process.StartInfo.Arguments = handBrakeCommand;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += new DataReceivedEventHandler(HandBrakeOutputDataReceived);
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
}
catch (Exception ex)
{
Logger.DebugException(ex.Message, ex);
return String.Empty;
}
return outputFile;
}
示例4: run
public void run()
{
var executableName = "starbound_server" + (StarryboundServer.IsMono ? "" : ".exe");
try
{
ProcessStartInfo startInfo = new ProcessStartInfo(executableName)
{
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
};
process = Process.Start(startInfo);
StarryboundServer.parentProcessId = process.Id;
File.WriteAllText("starbound_server.pid", process.Id.ToString());
process.OutputDataReceived += (sender, e) => parseOutput(e.Data);
process.ErrorDataReceived += (sender, e) => logStarboundError("ErrorDataReceived from starbound_server.exe: " + e.Data);
process.BeginOutputReadLine();
process.WaitForExit();
StarryboundServer.serverState = ServerState.Crashed;
}
catch (ThreadAbortException) { }
catch (Exception e)
{
StarryboundServer.logException("Unable to start starbound_server.exe, is this file in the same directory? " + e.ToString());
StarryboundServer.serverState = ServerState.Crashed;
}
}
示例5: 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);
}
}
示例6: RunCommandAndGetOutput
public bool RunCommandAndGetOutput(string command, string arguments, string workingFolder)
{
var p = new Process();
p.StartInfo.FileName = command;
p.StartInfo.Arguments = arguments;
p.StartInfo.WorkingDirectory = workingFolder;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += OutputDataReceived;
try
{
p.Start();
}
catch
{
return false;
}
p.BeginOutputReadLine(); // Async reading of output to prevent deadlock
if (p.WaitForExit(5000))
{
return p.ExitCode == 0;
}
return false;
}
示例7: OnStart
protected override void OnStart(string[] args)
{
WriteConfigFile();
process = new Process
{
StartInfo =
{
FileName = "metron.exe",
Arguments = @"--config=metron\config.json",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory
}
};
process.EnableRaisingEvents = true;
process.Exited += process_Exited;
var syslog = Syslog.Build(Config.Params(), eventSource);
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);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
示例8: GetEngineConfigOptions
public Dictionary<string, EngineConfigEntry> GetEngineConfigOptions(SpringPaths paths, string engine)
{
Trace.TraceInformation("Extracting configuration from Spring located in {0}", paths.GetEngineFolderByVersion(engine));
var sb = new StringBuilder();
var p = new Process();
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments += string.Format("--list-config-vars");
p.StartInfo.EnvironmentVariables["SPRING_DATADIR"] = paths.WritableDirectory;
p.StartInfo.EnvironmentVariables.Remove("SPRING_ISOLATED");
p.StartInfo.FileName = paths.GetSpringExecutablePath(engine);
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(paths.GetSpringExecutablePath(engine));
p.StartInfo.RedirectStandardOutput = true;
p.OutputDataReceived += (sender, args) => sb.AppendLine(args.Data);
p.Start();
p.BeginOutputReadLine();
p.WaitForExit(3000);
sb.AppendLine(); //append terminator
var text = sb.ToString();
int whereIsTable = text.IndexOf('{');
text = text.Substring(whereIsTable); // skip empty line or other info (if exist). Compatibility with Spring 94+
var data = JsonConvert.DeserializeObject<Dictionary<string, EngineConfigEntry>>(text);
return data;
}
示例9: Compile
/// <summary>
/// Compile the specified grammar
/// </summary>
/// <param name="grammarFile">Grammar file to compile</param>
/// <param name="outputFile">The name of the binary file output</param>
/// <remarks>The GOLD compiler outputs 2 versions of binary grammar tables:
/// CGT and EGT. The format generated depends on the file extension of the
/// output file (.cgt or .egt)</remarks>
public void Compile(string grammarFile, string outputFile)
{
//create a helper that will classify the error messages emitted by GOLD
inputFileName = grammarFile;
string text = slurpFile (inputFileName);
outputParser = new GoldBuildOutputParser (inputFileName);
//perform an initial parse on the file.
//this will get the error locations for us,
//since we can't get this info from the gold compiler
parser.Parse (text);
//launch the GOLD command line compiler
startInfo.Arguments = constructArguments (grammarFile, outputFile);
startInfo.WorkingDirectory = Path.GetDirectoryName (outputFile);
var p = new Process();
p.StartInfo = startInfo;
p.OutputDataReceived += outputHandler;
try
{
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
}
catch(Win32Exception)
{
var message = new CompilerMessage (MessageSeverity.Error,
goldCmdPath + " was not found on path",
string.Empty, 0, 0);
onCompileStepComplete (message);
}
}
示例10: ExecuteCommand
public static void ExecuteCommand(ExecutableInfo _info)
{
Debug.WriteLine($"Execucting: {_info.Command}");
//var processInfo = new ProcessStartInfo("cmd.exe", "/c " + _info.Command);
var processInfo = new ProcessStartInfo("openvpn.exe", _info.Command);
//processInfo.WorkingDirectory = _info.WorkingDirectory;
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
Process process = new Process();
process.StartInfo = processInfo;
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine(e.Data);
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine(e.Data);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
示例11: Execute
public Tuple<int, string> Execute(string fileName, string arguments)
{
var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = arguments,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
var sb = new StringBuilder();
process.OutputDataReceived += (sender, e) =>
{
sb.AppendLine(e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
sb.AppendLine(e.Data);
};
process.Exited += (sender, e) =>
{
};
process.EnableRaisingEvents = true;
process.Start();
process.StandardInput.Dispose();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
return Tuple.Create(process.ExitCode, sb.ToString());
}
示例12: Install
public static void Install()
{
string filename = GetOsDependantFilename();
var startInfo = new ProcessStartInfo(filename, InstallArgs)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
WorkingDirectory = Path.GetTempPath()
};
using (var process = new Process())
{
var output = new StringBuilder();
process.StartInfo = startInfo;
process.OutputDataReceived += (sender, e) =>
{
if (e.Data != null)
output.AppendLine(e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
ParseForElevatedPermissionsError(output.ToString());
Console.Out.WriteLine(output.ToString());
}
}
示例13: Start
public static bool Start()
{
var filename = Os.Tools.GetFullPath(VBusMonitorExecutable);
if (string.IsNullOrWhiteSpace(filename))
return false;
try
{
Stop();
VBusMonitorProcess = new Process();
VBusMonitorProcess.StartInfo.UseShellExecute = false;
VBusMonitorProcess.StartInfo.RedirectStandardOutput = true;
VBusMonitorProcess.StartInfo.FileName = filename;
VBusMonitorProcess.StartInfo.Arguments = VBusMonitorParameters;
VBusMonitorProcess.OutputDataReceived += VBusMonitorOnDataReceived;
VBusMonitorProcess.Start();
VBusMonitorProcess.BeginOutputReadLine();
}
catch
{
return false;
}
return true;
}
示例14: RunCommand
public static string RunCommand(string command, string cwd)
{
var process = new Process
{
StartInfo = new ProcessStartInfo("cmd")
{
Arguments = "/C " + command,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = cwd,
CreateNoWindow = true
}
};
var output = "";
process.OutputDataReceived += delegate(object o, DataReceivedEventArgs args)
{
if (args.Data == null) return;
output += args.Data;
if (args.Data[args.Data.Length - 1] != '\n') output += '\n';
};
process.ErrorDataReceived += delegate(object o, DataReceivedEventArgs args)
{
output += args.Data;
};
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
while (!process.HasExited) Thread.Sleep(10);
return output;
}
示例15: Run
public static void Run(string testArgument, DataReceivedEventHandler dataReceived = null)
{
string jarArgs = String.Format("{0} {1}", JavaArgs, testArgument);
var processInfo = new ProcessStartInfo(JavaExecutable, jarArgs)
{
CreateNoWindow = true,
UseShellExecute = false, // redirected streams
// redirect output stream
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true
};
_process = new Process { StartInfo = processInfo, EnableRaisingEvents = true };
_process.OutputDataReceived += ProcessOnOutputDataReceived;
_process.ErrorDataReceived += ProcessOnErrorDataReceived;
if (dataReceived != null)
{
_process.OutputDataReceived += dataReceived;
_process.ErrorDataReceived += dataReceived;
}
_process.Start();
Trace.WriteLine("Java process started.");
_process.BeginOutputReadLine();
_process.BeginErrorReadLine();
Trace.WriteLine("Waiting for Java process to exit.");
_process.WaitForExit();
Trace.WriteLine("Java process exited.");
_process.Close();
}