1

「n」個の実行可能ファイルを連鎖させ、「n-1」番目のexeの出力を「n」番目の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 クラスを使用できます。次のコードは、2 つの実行可能ファイルに対してトリックを行う必要があります。

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 に答える