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


C# Process.CancelErrorRead方法代码示例

本文整理汇总了C#中System.Diagnostics.Process.CancelErrorRead方法的典型用法代码示例。如果您正苦于以下问题:C# Process.CancelErrorRead方法的具体用法?C# Process.CancelErrorRead怎么用?C# Process.CancelErrorRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.Process的用法示例。


在下文中一共展示了Process.CancelErrorRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: StartAndWaitForExit

        public static ProcessOutput StartAndWaitForExit(Process process, string windowTitle)
        {
            List<string> errorOutput = new List<string>();
            List<string> standardOutput = new List<string>();

            process.ErrorDataReceived += (sender, args) => errorOutput.Add(args.Data);
            process.OutputDataReceived += (sender, args) => standardOutput.Add(args.Data);

            process.Start();

            process.BeginErrorReadLine();
            process.BeginOutputReadLine();

            process.WaitForExit();

            process.CancelErrorRead();
            process.CancelOutputRead();

            return new ProcessOutput(errorOutput, standardOutput);
        }
开发者ID:JohannesHoppe,项目名称:Mongo2Go,代码行数:20,代码来源:ProcessControl.cs

示例10: 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

示例11: CallProcess

        /// <summary>
        /// 启动程序
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="args"></param>
        /// <param name="isGetResults"> </param>
        private static String CallProcess(string fileName, string args, Boolean isGetResults)
        {
            var process = new Process();
            process.StartInfo.FileName = fileName;//设置运行的命令行文件
            process.StartInfo.Arguments = args;//设置命令参数
            process.StartInfo.CreateNoWindow = true;//不显示dos命令行窗口
            process.StartInfo.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
            process.StartInfo.RedirectStandardOutput = isGetResults;
            process.StartInfo.RedirectStandardError = isGetResults;

            // 启动
            process.Start();

            var result = new StringBuilder();

            if (isGetResults)
            {
                process.OutputDataReceived += (s, e) => result.AppendLine(e.Data);
                process.ErrorDataReceived += (s, e) => result.AppendLine(e.Data);

                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
            }

            // 等待完成
            process.WaitForExit();

            if (isGetResults)
            {
                process.CancelOutputRead();
                process.CancelErrorRead();

                return result.ToString();
            }
            else
            {
                return "";
            }
        }
开发者ID:wuqingman,项目名称:PPT2Vedio,代码行数:45,代码来源:Program.cs

示例12: CompileFromFileBatch

		private CompilerResults CompileFromFileBatch (CompilerParameters options, string[] fileNames)
		{
			if (null == options)
				throw new ArgumentNullException("options");
			if (null == fileNames)
				throw new ArgumentNullException("fileNames");

			CompilerResults results=new CompilerResults(options.TempFiles);
			Process mcs=new Process();

			// FIXME: these lines had better be platform independent.
			if (Path.DirectorySeparatorChar == '\\') {
				mcs.StartInfo.FileName = windowsMonoPath;
				mcs.StartInfo.Arguments = "\"" + windowsMcsPath + "\" " +
					BuildArgs (options, fileNames, ProviderOptions);
			} else {
				mcs.StartInfo.FileName="mcs";
				mcs.StartInfo.Arguments=BuildArgs(options, fileNames, ProviderOptions);
			}

			mcsOutput = new StringCollection ();
			mcsOutMutex = new Mutex ();
#if !NET_4_0
			/*
			 * !:. KLUDGE WARNING .:!
			 *
			 * When running the 2.0 test suite some assemblies will invoke mcs via
			 * CodeDOM and the new mcs process will find the MONO_PATH variable in its
			 * environment pointing to the net_2_0 library which will cause the runtime
			 * to attempt to load the 2.0 corlib into 4.0 process and thus mcs will
			 * fail. At the same time, we must not touch MONO_PATH when running outside
			 * the test suite, thus the kludge.
			 *
			 * !:. KLUDGE WARNING .:!
			 */
			if (Environment.GetEnvironmentVariable ("MONO_TESTS_IN_PROGRESS") != null) {
				string monoPath = Environment.GetEnvironmentVariable ("MONO_PATH");
				if (!String.IsNullOrEmpty (monoPath)) {
					const string basePath = "/class/lib/";
					const string profile = "net_2_0";
					var basePathIndex = monoPath.IndexOf (basePath, StringComparison.Ordinal);
					if (basePathIndex > 0 && basePathIndex + basePath.Length + profile.Length <= monoPath.Length) {
						var currentProfile = monoPath.Substring (basePathIndex + basePath.Length, profile.Length);
						if (currentProfile.Equals (profile, StringComparison.OrdinalIgnoreCase))
							monoPath = monoPath.Replace (basePath + currentProfile, basePath + "net_4_0");
					}
					mcs.StartInfo.EnvironmentVariables ["MONO_PATH"] = monoPath;
				}
			}
#endif
/*		       
			string monoPath = Environment.GetEnvironmentVariable ("MONO_PATH");
			if (monoPath != null)
				monoPath = String.Empty;

			string privateBinPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
			if (privateBinPath != null && privateBinPath.Length > 0)
				monoPath = String.Format ("{0}:{1}", privateBinPath, monoPath);

			if (monoPath.Length > 0) {
				StringDictionary dict = mcs.StartInfo.EnvironmentVariables;
				if (dict.ContainsKey ("MONO_PATH"))
					dict ["MONO_PATH"] = monoPath;
				else
					dict.Add ("MONO_PATH", monoPath);
			}
*/
			/*
			 * reset MONO_GC_PARAMS - we are invoking compiler possibly with another GC that
			 * may not handle some of the options causing compilation failure
			 */
			mcs.StartInfo.EnvironmentVariables ["MONO_GC_PARAMS"] = String.Empty;

			mcs.StartInfo.CreateNoWindow=true;
			mcs.StartInfo.UseShellExecute=false;
			mcs.StartInfo.RedirectStandardOutput=true;
			mcs.StartInfo.RedirectStandardError=true;
			mcs.ErrorDataReceived += new DataReceivedEventHandler (McsStderrDataReceived);
			
			try {
				mcs.Start();
			} catch (Exception e) {
				Win32Exception exc = e as Win32Exception;
				if (exc != null) {
					throw new SystemException (String.Format ("Error running {0}: {1}", mcs.StartInfo.FileName,
									Win32Exception.W32ErrorMessage (exc.NativeErrorCode)));
				}
				throw;
			}

			try {
				mcs.BeginOutputReadLine ();
				mcs.BeginErrorReadLine ();
				mcs.WaitForExit();
				
				results.NativeCompilerReturnValue = mcs.ExitCode;
			} finally {
				mcs.CancelErrorRead ();
				mcs.CancelOutputRead ();
				mcs.Close();
//.........这里部分代码省略.........
开发者ID:nlhepler,项目名称:mono,代码行数:101,代码来源:CSharpCodeCompiler.cs

示例13: CompileFromFileBatch


//.........这里部分代码省略.........

            try
            {
                mcs.Start();
            }
            catch (Exception e)
            {
                Win32Exception exc = e as Win32Exception;
                if (exc != null)
                {
                    /*throw new SystemException(String.Format("Error running {0}: {1}", mcs.StartInfo.FileName,
                                    Win32Exception.W32ErrorMessage(exc.NativeErrorCode)));*/
                }
                throw;
            }

            try
            {
#if NET_2_0
				mcs.BeginOutputReadLine ();
				mcs.BeginErrorReadLine ();
#else
                // If there are a few kB in stdout, we might lock
                mcs_output = mcs.StandardError.ReadToEnd();
                mcs_stdout = mcs.StandardOutput.ReadToEnd();
#endif
                mcs.WaitForExit();

                results.NativeCompilerReturnValue = mcs.ExitCode;
            }
            finally
            {
#if NET_2_0
				mcs.CancelErrorRead ();
				mcs.CancelOutputRead ();
#endif

                mcs.Close();
            }

#if NET_2_0
			StringCollection sc = mcsOutput;
#else
            mcsOutput = mcs_output.Split(System.Environment.NewLine.ToCharArray());
            StringCollection sc = new StringCollection();
#endif

            bool loadIt = true;
            foreach (string error_line in mcsOutput)
            {
#if !NET_2_0
                sc.Add(error_line);
#endif
                CompilerError error = CreateErrorFromString(error_line);
                if (error != null)
                {
                    results.Errors.Add(error);
                    if (!error.IsWarning)
                        loadIt = false;
                }
            }

            if (sc.Count > 0)
            {
                sc.Insert(0, mcs.StartInfo.FileName + " " + mcs.StartInfo.Arguments + Environment.NewLine);
开发者ID:AHuynh,项目名称:AIGAME,代码行数:66,代码来源:CSharp.cs

示例14: StartProcess

    /// <summary>
    /// Starts the comparison process.
    /// </summary>
    private void StartProcess()
    {
        if (comparexe != null && CurrentState == State.START)
            StopProcess();

        comparexe = new System.Diagnostics.Process();
        comparexe.StartInfo.CreateNoWindow = true;
        comparexe.StartInfo.UseShellExecute = false;
        comparexe.StartInfo.RedirectStandardOutput = true;
        comparexe.StartInfo.RedirectStandardError = true;
        comparexe.StartInfo.FileName = System.IO.Path.GetFullPath(_exe_filename);
        comparexe.StartInfo.Arguments =
            string.Format("{0} {1} {2} {3} {4}",
                  _ref_db_filename,
                  UseWeightsFile ? _wei_db_filename : "Null",
                  _rec_filename,
                  DrawPlots ? "-p" : "",
                  Properties.ActivityToString(ActionName));
        comparexe.EnableRaisingEvents = true;
        comparexe.OutputDataReceived += (sender, e) =>
        {
            lock (_buffer)
            {
                _buffer.Add(e.Data);
            }
        };
        comparexe.ErrorDataReceived += (sender, e) =>
        {
            if (e.Data != null)
                UnityEngine.Debug.LogError("Compare process says: " + e.Data);
        };
        comparexe.Exited += (sender, e) =>
        {
            comparexe.CancelOutputRead();
            comparexe.CancelErrorRead();
            UnityEngine.Debug.Log("Compare process exited!");
        };

        if(comparexe.Start())
        {
            comparexe.BeginOutputReadLine();
            comparexe.BeginErrorReadLine();
            StartCoroutine("StartConsole");
        }
    }
开发者ID:freddiehonohan,项目名称:HapticHealth,代码行数:48,代码来源:Compare_module.cs

示例15: StartAndWaitForReady

        /// <summary>
        /// Reads from Output stream to determine if process is ready
        /// </summary>
        public static ProcessOutput StartAndWaitForReady(Process process, int timeoutInSeconds, string processReadyIdentifier, string windowTitle)
        {
            if (timeoutInSeconds < 1 ||
                timeoutInSeconds > 10)
            {
                throw new ArgumentOutOfRangeException("timeoutInSeconds", "The amount in seconds should have a value between 1 and 10.");
            }

            List<string> errorOutput = new List<string>();
            List<string> standardOutput = new List<string>();
            bool processReady = false;

            process.ErrorDataReceived += (sender, args) => errorOutput.Add(args.Data);
            process.OutputDataReceived += (sender, args) =>
                {
                    standardOutput.Add(args.Data);

                    if (!string.IsNullOrEmpty(args.Data) &&
                        args.Data.Contains(processReadyIdentifier))
                    {
                        processReady = true;
                    }
                };

            process.Start();

            process.BeginErrorReadLine();
            process.BeginOutputReadLine();

            int lastResortCounter = 0;
            int timeOut = timeoutInSeconds * 10;
            while (!processReady)
            {
                Thread.Sleep(100);
                if (++lastResortCounter > timeOut)
                {
                    // we waited X seconds.
                    // for any reason the detection did not worked, eg. the identifier changed
                    // lets assume everything is still ok
                    break;
                }
            }

            process.CancelErrorRead();
            process.CancelOutputRead();

            return new ProcessOutput(errorOutput, standardOutput);
        }
开发者ID:JohannesHoppe,项目名称:Mongo2Go,代码行数:51,代码来源:ProcessControl.cs


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