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


C# Process.BeginOutputReadLine方法代码示例

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


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

示例1: Test1

	static void Test1 (Process p)
	{
		ManualResetEvent mre_exit = new ManualResetEvent (false);
		ManualResetEvent mre_output = new ManualResetEvent (false);
		ManualResetEvent mre_error = new ManualResetEvent (false);

		p.EnableRaisingEvents = true;
		p.Exited += (s, a) => mre_exit.Set ();

		p.Start ();

		p.OutputDataReceived += (s, a) => {
			if (a.Data == null) {
				mre_output.Set ();
				return;
			}
		};

		p.ErrorDataReceived += (s, a) => {
			if (a.Data == null) {
				mre_error.Set ();
				return;
			}
		};

		p.BeginOutputReadLine ();
		p.BeginErrorReadLine ();

		if (!mre_exit.WaitOne (10000))
			Environment.Exit (1);
		if (!mre_output.WaitOne (1000))
			Environment.Exit (2);
		if (!mre_error.WaitOne (1000))
			Environment.Exit (3);
	}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:35,代码来源:process-stress-3.cs

示例2: OnPostprocessAllAssets

    static void OnPostprocessAllAssets (string[] ia, string[] da, string[] ma, string[] mfap) {
        // skip if importing dll as already built
        if (Array.IndexOf(ia, "Assets/dll/scripts.dll") > -1) return;

        // setup the process
        var p = new Process();
        p.StartInfo.FileName = "/usr/bin/make";
        p.StartInfo.Arguments = "-C " + System.IO.Directory.GetCurrentDirectory() + "/Assets/Editor/";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.RedirectStandardError = true;

        // assign events
        p.OutputDataReceived +=
            new DataReceivedEventHandler((o, e) => {
                if (e.Data != null) {
                    UnityEngine.Debug.Log(e.Data);
                }
            });
        p.ErrorDataReceived +=
            new DataReceivedEventHandler((o, e) => {
                if (e.Data != null) {
                    UnityEngine.Debug.LogError(e.Data);
                }
            });

        // start to process and output/error reading
        p.Start();
        p.BeginOutputReadLine();
        p.BeginErrorReadLine();
    }
开发者ID:shockham,项目名称:unity_fsharp_skeleton,代码行数:31,代码来源:BuildFSharp.cs

示例3: RunProcess

	static bool RunProcess (string runtimeEngine, int numLines)
	{
		string stderr, stdout;
		sb = new StringBuilder ();

		string program = Path.Combine (AppDomain.CurrentDomain.BaseDirectory,
			"output.exe");

		Process proc = new Process ();
		if (!string.IsNullOrEmpty (runtimeEngine)) {
			proc.StartInfo.FileName = runtimeEngine;
			proc.StartInfo.Arguments = string.Format (CultureInfo.InvariantCulture,
				"\"{0}\" {1}", program, numLines);
		} else {
			proc.StartInfo.FileName = program;
			proc.StartInfo.Arguments = string.Format (CultureInfo.InvariantCulture,
				 "{0}", numLines);
		}
		proc.StartInfo.UseShellExecute = false;
		proc.StartInfo.RedirectStandardOutput = true;
		proc.StartInfo.RedirectStandardError = true;
		proc.OutputDataReceived += new DataReceivedEventHandler (OutputHandler);
		proc.Start ();

		proc.BeginOutputReadLine ();
		stderr = proc.StandardError.ReadToEnd ();
		proc.WaitForExit ();

		stdout = sb.ToString ();

		string expectedResult = "STDOUT => 1" + Environment.NewLine +
			"STDOUT => 2" + Environment.NewLine + "STDOUT => 3" +
			Environment.NewLine + "STDOUT => 4" + Environment.NewLine +
			" " + Environment.NewLine + "STDOUT => 6" + Environment.NewLine +
			"STDOUT => 7" + Environment.NewLine + "STDOUT => 8" +
			Environment.NewLine + "STDOUT => 9" + Environment.NewLine;
		if (stdout != expectedResult) {
			Console.WriteLine ("expected:");
			Console.WriteLine (expectedResult);
			Console.WriteLine ("was:");
			Console.WriteLine (stdout);
			return false;
		}

		expectedResult = "STDERR => 1" + Environment.NewLine +
			"STDERR => 2" + Environment.NewLine + "STDERR => 3" +
			Environment.NewLine + "STDERR => 4" + Environment.NewLine +
			" " + Environment.NewLine + "STDERR => 6" + Environment.NewLine +
			"STDERR => 7" + Environment.NewLine + "STDERR => 8" +
			Environment.NewLine + "STDERR => 9" + Environment.NewLine;
		if (stderr != expectedResult) {
			Console.WriteLine ("expected:");
			Console.WriteLine (expectedResult);
			Console.WriteLine ("was:");
			Console.WriteLine (stderr);
			return false;
		}

		return true;
	}
开发者ID:mono,项目名称:gert,代码行数:60,代码来源:test.cs

示例4: ApplyShader

    static bool ApplyShader(string test_name, string shader, string input, string result, string extra)
    {
        Process applyShader = new Process ();
        applyShader.StartInfo.FileName = "mono";
        applyShader.StartInfo.UseShellExecute = false;
        applyShader.StartInfo.Arguments = string.Format ("../src/shader.exe {0} {1} {2} {3}", extra, shader, input, result);
        applyShader.StartInfo.RedirectStandardError = true;
        applyShader.StartInfo.RedirectStandardOutput = true;

        var stdout = new StringBuilder ();
        var stderr = new StringBuilder ();
        applyShader.OutputDataReceived += (s, e) => { if (e.Data.Trim ().Length > 0) stdout.Append("\t").Append (e.Data).Append ("\n"); };
        applyShader.ErrorDataReceived += (s, e) => { if (e.Data.Trim ().Length > 0) stderr.Append("\t").Append (e.Data).Append ("\n"); };

        applyShader.Start ();
        applyShader.BeginOutputReadLine ();
        applyShader.BeginErrorReadLine ();

        applyShader.WaitForExit ();
        var exitCode = applyShader.ExitCode;
        applyShader.Dispose ();
        if (exitCode != 0)
            errorList.Add (String.Format ("Test {0} failed with:\n{1}{2}", test_name, stdout, stderr));
        return exitCode == 0;
    }
开发者ID:kumpera,项目名称:PixelMagic,代码行数:25,代码来源:TestRunner.cs

示例5: Test2

	static void Test2 (Process p)
	{
		StringBuilder sb = new StringBuilder ();
		ManualResetEvent mre_output = new ManualResetEvent (false);

		p.Start ();

		p.OutputDataReceived += (s, a) => {
			if (a.Data == null) {
				mre_output.Set ();
				return;
			}

			sb.Append (a.Data);
		};

		p.BeginOutputReadLine ();

		if (!p.WaitForExit (1000))
			Environment.Exit (4);
		if (!mre_output.WaitOne (1000))
			Environment.Exit (5);

		if (sb.ToString () != "hello") {
			Console.WriteLine ("process output = '{0}'", sb.ToString ());
			Environment.Exit (6);
		}
	}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:28,代码来源:process-stress-2.cs

示例6: LaunchAdapter

    private static Process LaunchAdapter(int adaptee, int adapted)
    {
        var temp = Path.GetTempFileName() + ".ensimea.exe";
        File.Copy(@"%SCRIPTS_HOME%\ensimea.exe".Expand(), temp);

        var psi = new ProcessStartInfo();
        psi.FileName = temp;
        psi.Arguments = String.Format("{0} {1}", adaptee, adapted);
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true;

        var p = new Process();
        p.StartInfo = psi;
        p.OutputDataReceived += (sender, args) => { if (args.Data != null) Console.WriteLine(args.Data); };
        p.ErrorDataReceived += (sender, args) => { if (args.Data != null) Console.WriteLine(args.Data); };

        if (p.Start()) {
          p.BeginOutputReadLine();
          p.BeginErrorReadLine();
          return p;
        } else {
          return null;
        }
    }
开发者ID:xeno-by,项目名称:dotwindows,代码行数:25,代码来源:ensime.cs

示例7: Start

 void Start()
 {
     process = new System.Diagnostics.Process ();
     process.StartInfo.FileName = @"..\wiiboard-client\wiiboard-client\bin\Debug\wiiboard-client.exe";
     process.StartInfo.RedirectStandardOutput = true;
     process.EnableRaisingEvents = true;
     process.StartInfo.CreateNoWindow = true;
     process.StartInfo.UseShellExecute = false;
     process.OutputDataReceived += HandleOutputDataReceived;
     process.Start ();
     process.BeginOutputReadLine ();
 }
开发者ID:aleroddepaz,项目名称:project-gaming,代码行数:12,代码来源:PlayerMovement.cs

示例8: UpcomingCalenderListText

    public static void UpcomingCalenderListText()
    {
        // Initialize the process and its StartInfo properties.
        // The sort command is a console application that
        // reads and sorts text input.

        Process calenderProcess;
        calenderProcess = new Process();
        calenderProcess.StartInfo.FileName = exeLocation;

        // Set UseShellExecute to false for redirection.
        calenderProcess.StartInfo.UseShellExecute = false;

        // Redirect the standard output of the sort command.
        // This stream is read asynchronously using an event handler.
        calenderProcess.StartInfo.RedirectStandardOutput = true;
        calendarOutput = new StringBuilder("");

        // Set our event handler to asynchronously read the sort output.
        calenderProcess.OutputDataReceived += new DataReceivedEventHandler(CalendarUpcomingEventsOutputHandler);

        // Redirect standard input as well.  This stream
        // is used synchronously.
        calenderProcess.StartInfo.RedirectStandardInput = true;

        // Start the process.
        calenderProcess.Start();

        // Use a stream writer to synchronously write the sort input.
        // StreamWriter sortStreamWriter = sortProcess.StandardInput;

        // Start the asynchronous read of the sort output stream.
        calenderProcess.BeginOutputReadLine();

        // Wait for the sort process to write the sorted text lines.
        calenderProcess.WaitForExit();

        if (numOutputLines > 0)
        {
            // Write the formatted and sorted output to the console.
            UnityEngine.Debug.Log(" Calender Upcoming event results = " + numOutputLines);

            UnityEngine.Debug.Log(calendarOutput);
        }
        else
        {
            Console.WriteLine(" No entries found.");
        }

        calenderProcess.Close();
    }
开发者ID:VRDesk,项目名称:VirtualDesk,代码行数:51,代码来源:fetchCalender.cs

示例9: getPathDialog

    /// <summary>
    /// getPathDialogメソッド (コルーチン実行)
    /// </summary>
    /// <param name="script">スクリプト(AppleScript)</param>
    /// <param name="argv">スクリプト引数</param>
    /// <param name="onClosed">終了通知</param>
    public IEnumerator getPathDialog(string script, System.Action<string, string> onClosed)
    {
        Process fileDialog = new Process ();				// fileDialogプロセス
        StringBuilder path = new StringBuilder ();			// 取得したファイルパス
        StringBuilder errorMessage = new StringBuilder ();	// エラーメッセージ
        // プロセスの初期設定
        fileDialog.StartInfo = new ProcessStartInfo ()
        {
            FileName = "osascript",			// 実行app (osascript : Applescriptを実行するmac標準app)
            Arguments = script,				// 実行appへの引数 (スクリプト自体)
            CreateNoWindow = true,			// terminalは非表示にする
            UseShellExecute = false,		// シェル機能を使用しない
            RedirectStandardOutput = true,	// スクリプトからの戻り値を受信する
            RedirectStandardError = true,	// スクリプトのエラーメッセージを受信する
        };
        // スクリプト戻り値イベント設定
        fileDialog.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>  {
            // 戻り値がないときも呼び出される場合があるので,戻り値があるか判定
            if(string.IsNullOrEmpty(e.Data) == false) {
                // 戻り値はURLエンコードされているのでデコード
                path.Append(WWW.UnEscapeURL(e.Data));
                UnityEngine.Debug.Log(WWW.UnEscapeURL(e.Data));
            }
        };
        // スクリプトエラーメッセージ受信イベント設定
        fileDialog.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => {
            // エラーがないときも呼び出される場合があるので,エラーメッセージがあるか判定
            if(string.IsNullOrEmpty(e.Data) == false) {
                errorMessage.Append(e.Data);
                UnityEngine.Debug.Log(e.Data);
            }
        };
        // プロセススタート.
        fileDialog.Start ();
        fileDialog.BeginOutputReadLine ();
        fileDialog.BeginErrorReadLine ();

        // 1フレーム待機し,その後applescriptのACTIVATE命令を実行
        yield return null;
        Process.Start (new ProcessStartInfo () { FileName = "osascript", Arguments = FORCE_ACTIVATE });
        // fileDialogが終了するまで待機
        while (fileDialog.HasExited == false) {
            yield return null;
        }
        // プロセスを終了・破棄
        fileDialog.Close ();
        fileDialog.Dispose ();
        // 終了通知
        onClosed.Invoke (path.ToString (), errorMessage.ToString());
    }
开发者ID:gtacenterprise,项目名称:plen__motion_editor_for_Unity,代码行数:56,代码来源:FileChooser.cs

示例10: RunProcess

    public Task<int> RunProcess(string fileName, string arguments, Action<string> outputAction, Action<string> errorAction)
    {
        LogTo.Information(string.Format("Executing process: {0} {1}", fileName, arguments));
        var tcs = new TaskCompletionSource<int>();

        var process = new Process
        {
            StartInfo =
            {
                FileName = fileName,
                Arguments = arguments,
                CreateNoWindow = true,
                UseShellExecute = false,
                WindowStyle = ProcessWindowStyle.Hidden,
                RedirectStandardError = true,
                RedirectStandardOutput = true,
            },
            EnableRaisingEvents = true,
        };
        process.OutputDataReceived += (sender, args) =>
        {
            if (args.Data != null)
            {
                LogTo.Information(args.Data);
                outputAction(args.Data);
            }
        };
        process.ErrorDataReceived += (sender, args) =>
        {
            if (args.Data != null)
            {
                LogTo.Error(args.Data);
                errorAction(args.Data);
            }
        };
        process.Exited += (sender, args) =>
        {
            tcs.SetResult(process.ExitCode);
            //TODO: result
            process.Dispose();
        };

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

        return tcs.Task;
    }
开发者ID:nagyist,项目名称:PlatformInstaller,代码行数:48,代码来源:ProcessRunner.cs

示例11: ExecuteExample

 public void ExecuteExample(string example)
 {
     Process process = new Process();
     process.StartInfo.FileName = Path.Combine(TestContext.CurrentContext.TestDirectory, "Wyam.exe");
     process.StartInfo.Arguments = example;
     process.StartInfo.CreateNoWindow = true;
     process.StartInfo.UseShellExecute = false;
     process.StartInfo.RedirectStandardOutput = true;
     process.StartInfo.RedirectStandardError = true;
     process.OutputDataReceived += (s, e) => TestContext.Out.WriteLine(e.Data);
     process.ErrorDataReceived += (s, e) => TestContext.Out.WriteLine(e.Data);
     process.Start();
     process.BeginOutputReadLine();
     process.WaitForExit();
     Assert.AreEqual(0, process.ExitCode);
 }
开发者ID:ryanrousseau,项目名称:Wyam,代码行数:16,代码来源:ExamplesTests.cs

示例12: ReadAttachInfo

    // 启动代理读取Cell项
    public static string ReadAttachInfo(string code)
    {
        string stdOutput = "";
        string errOutput = "";

        Process agentProcess = new Process();
        agentProcess.StartInfo.FileName = "ExcelAccessAgent";       // ExcelAccessAgent.exe在同一目录下
        agentProcess.StartInfo.Arguments = Path.Combine(ToolManager.Instance.virtualWorkDir, ToolManager.Instance.HeroExcel) + " read " + code;
        agentProcess.StartInfo.CreateNoWindow = true;
        agentProcess.StartInfo.UseShellExecute = false;
        agentProcess.StartInfo.RedirectStandardOutput = true;
        agentProcess.StartInfo.RedirectStandardError = true;
        agentProcess.EnableRaisingEvents = false;

        agentProcess.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
        {
            stdOutput += e.Data;
        };

        agentProcess.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
        {
            errOutput += e.Data;
        };

        agentProcess.Start();
        agentProcess.BeginOutputReadLine();
        agentProcess.BeginErrorReadLine();
        agentProcess.WaitForExit();

        if (agentProcess.ExitCode != 0)
        {
            // 用户错误指示
            if (errOutput.Contains("找不到Code为"))
            {
                ToolManager.Instance.InfoStr = "Excel中没有采用此Spine的行!";
            }
            else if(errOutput.Contains("由另一进程使用"))
            {
                ToolManager.Instance.InfoStr = "Excel被别的程序打开,请先关闭";
            }

            Debug.LogError("ExcelAccessAgent遇到错误: " + errOutput);
            // System.Windows.Forms.MessageBox.Show(errOutput, "错误", System.Windows.Forms.MessageBoxButtons.OK);
            return "";
        }
        return stdOutput;
    }
开发者ID:Henry-T,项目名称:UnityPG,代码行数:48,代码来源:ExcelAccessAgent.cs

示例13: Generate

	void Generate(int level){
		int seed=UnityEngine.Random.Range(1,10);
		int n=1;
		int hardness=2;
		if(Level==0){ //easy
			hardness=3;
		}
		else if(Level==1){//Moderate
			hardness=10;
		}
		else if(Level==2){
			hardness=15;
		}
		try {
		 myProcess = new Process();
         myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
         myProcess.StartInfo.CreateNoWindow = true;
         myProcess.StartInfo.UseShellExecute = false;
		 myProcess.StartInfo.RedirectStandardOutput = true;
		 myProcess.StartInfo.FileName = (System.Environment.CurrentDirectory )+Path.DirectorySeparatorChar +"rubik3Sticker.generator";
		 myProcess.EnableRaisingEvents = true;
		 myProcess.StartInfo.WorkingDirectory = (System.Environment.CurrentDirectory )+Path.DirectorySeparatorChar;
		 myProcess.StartInfo.Arguments = seed.ToString()+" "+n.ToString()+" "+hardness.ToString();
		 myProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
        {
            if (!String.IsNullOrEmpty(e.Data))
            {
				print(e.Data);
				RandomGenerated+=e.Data;
            }
        });
        myProcess.Start();
		myProcess.BeginOutputReadLine();
         } catch (Exception e){
             print(e);        
         }
		 myProcess.WaitForExit();
		 myProcess=null;
		 words = RandomGenerated.Split(delimiterChars);
		 foreach (string s in words){
			RandomGeneratedColors.Add(s);
        }
		Globals.RandomGeneratedFlag=true;
		Globals.ManualInputFlag=false;
		Globals.LoadFlag=false;
	}
开发者ID:msLangdon95,项目名称:GraduationProject,代码行数:46,代码来源:RandomGeneration.cs

示例14: Generate

	void Generate(int level){
		RandomGeneratedFlag=true;
		int seed=UnityEngine.Random.Range(1,10);
		int n=1;
		int hardness=1;
		if(Level==0){ //easy
			hardness=5;
		}
		else if(Level==1){//Moderate
			hardness=10;
		}
		else if(Level==2){
			hardness=15;
		}
		try {
		 myProcess = new Process();
         myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
         myProcess.StartInfo.CreateNoWindow = true;
         myProcess.StartInfo.UseShellExecute = false;
		 myProcess.StartInfo.RedirectStandardOutput = true;
         myProcess.StartInfo.FileName = "C:\\Users\\Sam\\Desktop\\Test\\rubik3Sticker.generator";
         myProcess.EnableRaisingEvents = true;
		 myProcess.StartInfo.WorkingDirectory = "C:\\Users\\Sam\\Desktop\\Test\\";
		 myProcess.StartInfo.Arguments = seed.ToString()+" "+n.ToString()+" "+hardness.ToString();
		 myProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
        {
            if (!String.IsNullOrEmpty(e.Data))
            {
                //print(e.Data);
				RandomGenerated+=e.Data;
            }
        });
        myProcess.Start();
		myProcess.BeginOutputReadLine();
         } catch (Exception e){
             print(e);        
         }
		 myProcess.WaitForExit();

		 words = RandomGenerated.Split(delimiterChars);
		 foreach (string s in words){
			RandomGeneratedColors.Add(s);
        }
	}
开发者ID:msLangdon95,项目名称:GraduationProject,代码行数:44,代码来源:LevelHardness.cs

示例15: WriteAttachInfo

    // 启动代理写入数据项
    public static bool WriteAttachInfo(string code, string value)
    {
        string stdOutput = "";
        string errOutput = "";

        Process agentProcess = new Process();
        agentProcess.StartInfo.FileName = "ExcelAccessAgent";
        agentProcess.StartInfo.Arguments =  Path.Combine(ToolManager.Instance.virtualWorkDir, ToolManager.Instance.HeroExcel) + " write " + code + " " + value;
        agentProcess.StartInfo.CreateNoWindow = true;
        agentProcess.StartInfo.UseShellExecute = false;
        agentProcess.StartInfo.RedirectStandardOutput = true;
        agentProcess.StartInfo.RedirectStandardError = true;
        agentProcess.EnableRaisingEvents = false;

        agentProcess.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
        {
            stdOutput += e.Data;
        };

        agentProcess.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
        {
            errOutput += e.Data;
        };

        agentProcess.Start();
        agentProcess.BeginOutputReadLine();
        agentProcess.BeginErrorReadLine();
        agentProcess.WaitForExit();

        if (agentProcess.ExitCode != 0)
        {
            // 用户错误指示
            if (errOutput.Contains("System.IO.IOException"))
            {
                ToolManager.Instance.InfoStr = "Excel被别的程序打开,请先关闭";
            }

            Debug.LogError("ExcelAccessAgent遇到错误: " + errOutput);

            return false;
        }
        return true;
    }
开发者ID:Henry-T,项目名称:UnityPG,代码行数:44,代码来源:ExcelAccessAgent.cs


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