执行过程链 [英] Execute Process Chain

查看:103
本文介绍了执行过程链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public void ExecuteProcessChain(string[] asProcesses, string sInRedirect, string sOutRedirect)
    {
            Process p1 = new Process();
            p1.StartInfo.UseShellExecute = false;
            p1.StartInfo.RedirectStandardOutput = true;
            p1.StartInfo.FileName = asProcesses[0];
            p1.Start();
            StreamReader sr = p1.StandardOutput;
            string s, xxx = "";
            while ((s = sr.ReadLine()) != null)
                Console.WriteLine("sdfdsfs");
                //xxx += s+"\n";
            p1.StartInfo.RedirectStandardInput = true;
            p1.StartInfo.RedirectStandardOutput = false;
            p1.StartInfo.FileName = asProcesses[1];
            p1.Start();
            StreamWriter sw = p1.StandardInput;
            sw.Write(xxx);
            sw.Close();
            sr.Close();

    }



我想执行钙|钙,但是当我这样做,它就会被卡在该行,而((S = sr.ReadLine())!= NULL)只有经过我关闭代码继续计算器。我既需要计算器共同努力。你有想法怎么做?

I am trying to execute "calc|calc" but when I do so , it gets stuck at the line while ((s = sr.ReadLine()) != null) and only after I close the calculator the code continues. I need both calculators to work together. do you have idea how to do that?

推荐答案

的ReadLine 正在读从第一计算的输出。计算器不发送任何输出。因此,的ReadLine 将永远不会返回,因此接下来的钙将无法启动。当第一个计算终止,的ReadLine 不能再从第一个计算读取,因此返回null。它返回后,代码可以启动第二次计算。

ReadLine is reading from the output of the first calc. Calc doesn't send any output. So, ReadLine will never return and thus the next calc will not start. When the first calc terminates, ReadLine can no longer read from the first calc, so returns null. After it has returned, the code can start the second calc.

您可以不从第一钙读或读异步。
你可能希望参考异步的ReadLine 如何
阅读异步。

You can either not read from the first calc or read asynchronously. You might want to refer to Async ReadLine on how to read asynchronously.

您可以或者你开始打电话之前先p2的第二钙的ReadLine

You could alternatively start the second calc with p2 before you start calling ReadLine.

这篇关于执行过程链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆