6
C#アプリケーションからantスクリプトを呼び出そうとしています。私はコンソールウィンドウをポップアップしたままにしておきたい(今はコマンドプロンプトを呼び出しているが、最終的には最大1時間かかってしまうantスクリプトを呼びたい)。これは私がoriginalから変更された私が使用しているコードです:コマンドプロンプトを表示して終了ウィンドウを開く
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スクリプトによって生成されたコンテンツを読むことには興味がありません。私は誰も私のために私の仕事をするように頼んでいませんが、私はしばらくの間この頭に頭を叩いているので、どんな助けも大いに感謝されるでしょう!
これはうまくいきました。今日のほとんどは、それに苛まれていました。どのように複数のコマンドで動作するようにするか考えていますか?特に空白のもの:cd c:\\ users \\ – Stubbs
スペースを含むコマンドは、そのまま解釈する必要があります。バッチファイルにコマンドを送信するか、StandardInputStreamにコマンドを送信する必要があるかもしれませんが、私はそれをひとつの文字列ですべて送信することはできません。 –
[link](http://stackoverflow.com/questions/5591382/how-to-execute-multiple-cammand-in-command-prompt-using-c-sharp)のように複数のパラメータを送信することもできます。これにより、ディレクトリが変更され、4つのパラメータがバッチファイルに渡されます。誰かに役立つかもしれない。 – Stubbs