1

我想链接'n'个可执行文件,第'n-1'个exe的输出作为'n'th exe的输入传递。我打算使用 XML 文件来配置可执行位置、路径、i/p、o/p 等。

我的问题是当有多个输出和多个输入(命令行参数)时如何将“n-1”链接到“n”。我对此有一些想法,但想看看其他人的想法,也许我会知道一种有效/快速的方法来做到这一点。灵活的 xml 配置的设计模式会有所帮助。

我将使用的伪 XML 结构

<executables>
  <entity position="1" exePath="c:\something1.exe">
     <op><name="a" value=""></op>
  </entity>
  <entity position="2" exePath="c:\something2.exe">
   <ip><name="a"></ip>
   <op><name="b"  value=""></op>
  </entity>
  <entity position="3" exePath="c:\something3.exe">
   <ip><name="b"</ip>
  </entity>
</executables>

在配置这些之前,我会了解 i/p 和 o/p。上下文是我可能会或可能不会在我将使用的某些类型的链接中包含某些节点,从而有效地创建灵活的串行 exe 执行路径。

4

1 回答 1

1

您可以为此使用 System.Diagnostics.Process 类。以下代码应该对两个可执行文件起作用:

using (Process outerProc = new Process())
{
    outerProc.StartInfo.FileName = "something1.exe";
    outerProc.StartInfo.UseShellExecute = false;
    outerProc.StartInfo.RedirectStandardOutput = true;
    outerProc.Start();

    string str = outerProc.StandardOutput.ReadToEnd();

    using(Process innerProc = new Process())
    {
        innerProc.StartInfo.FileName = "something2.exe";
        innerProc.StartInfo.UseShellExecute = false;
        innerProc.StartInfo.RedirectStandardInput = true;
        innerProc.Start();

        innerProc.StandardInput.Write(str);
        innerProc.WaitForExit();
    }

    outerProc.WaitForExit();
}

您可以轻松修改它以适应您的“n-1”到“n”的情况。

于 2012-05-15T23:43:18.807 回答