本文整理汇总了C#中System.Diagnostics.Process.CancelOutputRead方法的典型用法代码示例。如果您正苦于以下问题:C# Process.CancelOutputRead方法的具体用法?C# Process.CancelOutputRead怎么用?C# Process.CancelOutputRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.CancelOutputRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public int Run(string srcpath)
{
Process p;
p = new Process();
p.StartInfo.FileName = ILASMpath;
p.StartInfo.Arguments = srcpath;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.OutputDataReceived += new DataReceivedEventHandler(OnOutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(OnErrorDataReceived);
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
p.CancelErrorRead();
p.CancelOutputRead();
return p.ExitCode;
}
示例2: RunProcessAndRedirectToLogger
public static int RunProcessAndRedirectToLogger(string command, string parameters, string workingDirectory, LoggerResult logger)
{
var process = new Process
{
StartInfo = new ProcessStartInfo(command)
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
WorkingDirectory = workingDirectory,
Arguments = parameters,
}
};
process.Start();
DataReceivedEventHandler outputDataReceived = (_, args) => LockProcessAndAddDataToLogger(process, logger, false, args);
DataReceivedEventHandler errorDataReceived = (_, args) => LockProcessAndAddDataToLogger(process, logger, true, args);
process.OutputDataReceived += outputDataReceived;
process.ErrorDataReceived += errorDataReceived;
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
process.CancelOutputRead();
process.CancelErrorRead();
process.OutputDataReceived -= outputDataReceived;
process.ErrorDataReceived -= errorDataReceived;
return process.ExitCode;
}
示例3: GetDbDumpTask
private static Task GetDbDumpTask(Config config)
{
return Task.Factory.StartNew(() =>
{
var process = new Process
{
StartInfo = new ProcessStartInfo(config.MongoDumpPath, config.MongoDumpArgs)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
}
};
process.OutputDataReceived += (a, e) => Trace.TraceInformation(e.Data);
process.ErrorDataReceived += (a, e) => Trace.TraceEvent(TraceEventType.Error, 0, e.Data);
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelErrorRead();
process.CancelOutputRead();
process.Close();
Trace.TraceInformation("Dump completed!");
});
}
示例4: Run
public void Run()
{
var command = "/C node \"" +
config.OptimizerPath + "\" -o \"" +
config.BuildFilePath + "\"";
var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "cmd.exe",
Arguments = command,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
},
EnableRaisingEvents = true
};
process.OutputDataReceived += (s, e) => {
Console.WriteLine(e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelOutputRead();
}
示例5: RunProcess
public static void RunProcess(string name, string args, IList<string> stdout)
{
var processStartInfo = new ProcessStartInfo
{
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
FileName = name,
Arguments = args
};
var process = new Process
{
StartInfo = processStartInfo,
EnableRaisingEvents = true
};
process.OutputDataReceived += delegate (object sender, DataReceivedEventArgs e)
{
stdout.Add(e.Data);
Console.WriteLine(e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelOutputRead();
}
示例6: Compile
public CSharpCompilerResult Compile(CSharpCompilerArgs args)
{
if (args == null)
throw new ArgumentNullException("args");
var exitCode = 0;
var outputText = string.Empty;
var invocationError = null as Exception;
var warnings = new List<string>();
var errors = new List<string>();
var framework = new FrameworkVersion40Info();
var compilerArgs = this.GetCompilerArgString(args);
var psi = new ProcessStartInfo(framework.CSharpCompilerBinFilepath, compilerArgs);
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.WorkingDirectory = args.WorkDir;
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
var process = new Process();
process.StartInfo = psi;
process.ErrorDataReceived += (s, e) =>
{
Console.WriteLine(e.Data);
};
process.OutputDataReceived += (s, e) =>
{
Console.WriteLine(e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
process.CancelErrorRead();
process.CancelOutputRead();
exitCode = process.ExitCode;
process.Dispose();
process = null;
return new CSharpCompilerResult(exitCode,
invocationError,
outputText,
args.OutputFilepath,
warnings,
errors);
}
示例7: Run
public void Run()
{
if(File.Exists(config.OutputPath)) {
options.Log("Deleting old output file.", true);
var info = new FileInfo(config.OutputPath);
using(info.Create()) {
//effectively deletes the contents of the file
//calling delete seamed to break the following optimizer code, not sure why
}
}
if(!File.Exists(config.OptimizerPath)) {
using(var stream = IO.ReadFromResource("r.js"))
using(var file = File.OpenWrite(config.OptimizerPath)) {
stream.CopyTo(file);
}
}
if(options.Loader == Options.LoaderOptions.Almond) {
if(!File.Exists(config.AlmondPath)) {
using(var stream = IO.ReadFromResource("almond-custom.js"))
using(var file = File.OpenWrite(config.AlmondPath)) {
stream.CopyTo(file);
}
}
}
var command = "/C node \"" +
config.OptimizerPath + "\" -o \"" +
config.BuildFilePath + "\"";
var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "cmd.exe",
Arguments = command,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
},
EnableRaisingEvents = true
};
process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
process.ErrorDataReceived += (s, e) => Console.Error.WriteLine(e.Data);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
process.CancelOutputRead();
process.CancelErrorRead();
}
示例8: WaitForExit
private static void WaitForExit(Process process)
{
process.ErrorDataReceived += (sender, args) => Trace.TraceError("NODEJS: {0}".E(args.Data));
process.OutputDataReceived += (sender, args) => Trace.TraceInformation("NODEJS: {0}".I(args.Data));
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelErrorRead();
process.CancelOutputRead();
}
示例9: Run
public static string Run(string path, string args, out string error, bool readOutputByLines = false)
{
try
{
using (Process process = new Process())
{
Console.WriteLine("Run: " + path);
Console.WriteLine("Args: " + args);
process.StartInfo.FileName = path;
process.StartInfo.Arguments = args;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
var reterror = "";
var retout = "";
process.OutputDataReceived += (sender, outargs) =>
{
if (retout != "" && outargs.Data != "") retout += "\r\n";
retout += outargs.Data;
Console.WriteLine("stdout: {0}", retout);
};
process.ErrorDataReceived += (sender, errargs) =>
{
if (reterror != "" && errargs.Data != "") reterror += "\r\n";
reterror += errargs.Data;
Console.WriteLine("stderr: {0}", reterror);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
process.CancelOutputRead();
process.CancelErrorRead();
error = reterror;
if (process.ExitCode != 0)
throw new Exception("Exit Code is not 0");
return readOutputByLines ? string.Empty : retout.Trim().Replace(@"\\", @"\");
}
}
catch (Exception exception)
{
error = string.Format("Calling {0} caused an exception: {1}.", path, exception.Message);
return string.Empty;
}
}
示例10: RunTestProcess
private static void RunTestProcess(string processPath)
{
var processStartInfo = new ProcessStartInfo(processPath)
{
RedirectStandardOutput = true,
UseShellExecute = false,
};
var process = new Process()
{
StartInfo = processStartInfo,
};
process.OutputDataReceived += Process_OutputDataReceived;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelOutputRead();
}
示例11: Main
static void Main(string[] args)
{
Console.WriteLine("Please enter your file path to search.");
Console.Write("> ");
string path = Console.ReadLine();
string[] filenames = Directory.GetFiles(path, "*.mkv", SearchOption.AllDirectories);
foreach (string s in filenames)
{
if (File.Exists(s))
{
currentFile = s;
Process p = new Process();
p.StartInfo.Arguments = "-i " + "\"" + s + "\"";
p.StartInfo.FileName = "ffmpeg.exe";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.ErrorDataReceived += P_ErrorDataReceived;
p.OutputDataReceived += P_ErrorDataReceived;
p.WaitForExit();
if (p.HasExited)
{
p.CancelErrorRead();
p.CancelOutputRead();
p.Close();
}
}
}
convertFiles = convertFiles.Distinct().ToList();
Console.WriteLine("File to convert: " + convertFiles.Count);
runThread1();
runThread2();
runThread3();
runThread4();
Console.Write("Press any key to exit.");
Console.ReadKey();
}
示例12: Run
public void Run()
{
if(File.Exists(config.OutputPath)) {
options.Log("Deleting old output file.", true);
File.Delete(config.OutputPath);
}
if(!File.Exists(config.OptimizerPath)) {
using(var stream = IO.ReadFromResource("r.js"))
using(var file = File.OpenWrite(config.OptimizerPath)) {
stream.CopyTo(file);
}
}
if(options.Almond) {
if(!File.Exists(config.AlmondPath)) {
using(var stream = IO.ReadFromResource("almond-custom.js"))
using(var file = File.OpenWrite(config.AlmondPath)) {
stream.CopyTo(file);
}
}
}
var command = "/C node \"" +
config.OptimizerPath + "\" -o \"" +
config.BuildFilePath + "\"";
var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "cmd.exe",
Arguments = command,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
},
EnableRaisingEvents = true
};
process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelOutputRead();
}
示例13: Execute
public static string Execute(string program, string arguments)
{
StringBuilder outputBuilder;
ProcessStartInfo processStartInfo;
Process process;
outputBuilder = new StringBuilder();
processStartInfo = new ProcessStartInfo();
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.UseShellExecute = false;
processStartInfo.Arguments = arguments;
processStartInfo.FileName = program;
process = new Process();
process.StartInfo = processStartInfo;
// enable raising events because Process does not raise events by default
process.EnableRaisingEvents = true;
// attach the event handler for OutputDataReceived before starting the process
process.OutputDataReceived += new DataReceivedEventHandler
(
delegate(object sender, DataReceivedEventArgs e)
{
// append the new data to the data already read-in
outputBuilder.Append(e.Data);
outputBuilder.Append(Environment.NewLine);
}
);
// start the process
// then begin asynchronously reading the output
// then wait for the process to exit
// then cancel asynchronously reading the output
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelOutputRead();
// use the output
string output = outputBuilder.ToString();
return output;
}
示例14: Spawn
public bool Spawn(String args, out string result)
{
StringBuilder outputBuilder;
ProcessStartInfo processStartInfo;
Process process;
outputBuilder = new StringBuilder();
processStartInfo = new ProcessStartInfo(EXE_IN_FULL_PATH, args);
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.UseShellExecute = false;
processStartInfo.WindowStyle = ProcessWindowStyle.Normal;
using (process = new Process())
{
process.StartInfo = processStartInfo;
process.EnableRaisingEvents = true;
process.OutputDataReceived += new DataReceivedEventHandler
(
delegate(object sender, DataReceivedEventArgs e)
{
outputBuilder.Append(e.Data);
}
);
process.Start();
process.BeginOutputReadLine();
bool terminated = process.WaitForExit(10*1000);
process.CancelOutputRead();
if (!terminated)
{
process.Kill();
result = null;
return false;
}
else
{
result = outputBuilder.ToString();
return true;
}
}
}
示例15: NmapExec
private void NmapExec(object sender, DoWorkEventArgs e)
{
Process compiler = new Process();
compiler.StartInfo.FileName = NmapLocation;
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardInput = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.StartInfo.RedirectStandardError = true;
compiler.StartInfo.CreateNoWindow = true;
compiler.OutputDataReceived += OutputDataHandler;
compiler.ErrorDataReceived += OutputDataHandler;
compiler.StartInfo.Arguments = (string)e.Argument;
compiler.Start();
compiler.BeginOutputReadLine();
compiler.BeginErrorReadLine();
compiler.WaitForExit();
compiler.CancelOutputRead();
compiler.CancelErrorRead();
compiler.Close();
}