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


C# Process.CancelOutputRead方法代码示例

本文整理汇总了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;
        }
开发者ID:quwahara,项目名称:Nana,代码行数:25,代码来源:ILASMRunner.cs

示例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;
        }
开发者ID:cg123,项目名称:xenko,代码行数:33,代码来源:ShellHelper.cs

示例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!");
            });
        }
开发者ID:mikalai-silivonik,项目名称:bnh,代码行数:28,代码来源:Program.cs

示例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();
        }
开发者ID:mickdelaney,项目名称:Durandal,代码行数:26,代码来源:RJSRunner.cs

示例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();
        }
开发者ID:waybuild,项目名称:wb,代码行数:29,代码来源:Fs.cs

示例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);
        }
开发者ID:juankakode,项目名称:zenmake,代码行数:58,代码来源:CSharpCompiler.cs

示例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();
        }
开发者ID:nicolaihald,项目名称:Durandal,代码行数:53,代码来源:RJSRunner.cs

示例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();
        }
开发者ID:h5n1,项目名称:SolarTournament,代码行数:15,代码来源:ProcessControl.cs

示例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;
            }
        }
开发者ID:grbd,项目名称:QtSharp,代码行数:48,代码来源:ProcessHelper.cs

示例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();
 }
开发者ID:taynes13,项目名称:SimdTest,代码行数:17,代码来源:Program.cs

示例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();

        }
开发者ID:Paymh,项目名称:MultiThreadedDTSConverter,代码行数:45,代码来源:Program.cs

示例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();
        }
开发者ID:jigjosh,项目名称:Durandal,代码行数:45,代码来源:RJSRunner.cs

示例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;
        }
开发者ID:woloski,项目名称:SiteMonitR,代码行数:44,代码来源:Server.cs

示例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;
                }
            }
        }
开发者ID:DuBin1988,项目名称:anjian_phone_server,代码行数:42,代码来源:CardService.cs

示例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();
 }
开发者ID:sedmoy,项目名称:verda-v1,代码行数:20,代码来源:NmapWorker.cs


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