7

C#アプリケーションからantスクリプトを呼び出そうとしています。コンソールウィンドウをポップアップして表示したままにします(今はコマンドプロンプトを呼び出していますが、最終的にはantスクリプトを呼び出します。これには最大1時間かかる場合があります)。これは私が使用しているコードであり、元のコードから変更したものです。

public void ExecuteCommandSync(object command)
{
    try
    {
        // create the ProcessStartInfo using "cmd" as the program to be run,
        // and "/c " as the parameters.
        // Incidentally, /c tells cmd that we want it to execute the command that follows,
        // and then exit.
        System.Diagnostics.ProcessStartInfo procStartInfo =
        new System.Diagnostics.ProcessStartInfo("cmd", "/k " + command);

        // The following commands are needed to redirect the standard output.
        // This means that it will be redirected to the Process.StandardOutput StreamReader.
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;
        // Do not create the black window.
        procStartInfo.CreateNoWindow = false;
        // Now we create a process, assign its ProcessStartInfo and start it
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo = procStartInfo;

        proc.Start();
        proc.WaitForExit();

    }
    catch (Exception objException)
    {
        Console.WriteLine(objException);
    }
}

また、最大5つのパラメーターを渡したいのですが、現在は、何が起こっているかを確認するのに十分な時間ウィンドウを開いたままにしておくことに関心があり、antスクリプトによって生成されたコンテンツを読み取ることには興味がありません。誰かに仕事を依頼したくないのですが、しばらくこれに頭を悩ませてきたので、助けていただければ幸いです!

4

1 に答える 1

8

この行;

procStartInfo.RedirectStandardOutput = true;

ウィンドウが閉じる原因です。この行を削除するか、 Process.StandardOutput にハンドラーを追加して、コンテンツを別の場所で読み取ります。

string t = proc.StandardOutput.ReadToEnd();
于 2012-09-28T01:35:49.527 に答える