0

C# コンソール プログラムを作成し、別のコソールでいくつかのバッチ処理を実行したいと考えています。

そのため、コンソールに書き込むメインプログラムがあり、ある時点で別のプログラムでバッチ処理を実行したいと考えています。

メインコンソールでバッチ処理を実行する方法は知っていますが、別のコンソールでそれを実行したいのですが、それが私の質問です。

どうすればそれを作ることができますか?

編集: StreaWriter を使用して、コンソールに次のように書き込みます。

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;

process.StartInfo = startInfo;
process.Start();

using (StreamWriter writer = process.StandardInput)
{
    if (writer.BaseStream.CanWrite)
    {
        // commands...
    }
}
4

1 に答える 1

3

Process.Start を使用します。

Process.Start("cmd.exe", "yourcommandhere");
于 2013-05-06T11:18:49.943 に答える