Przesyłanie wielu argumentów do cmd.exe

0

Cześć,

Mam pytanie. Mam taki kod w Windows Form App: (niżej). Problem w tym, że proces wywoływany jest w pętli, przez co uruchamia trzy instancje cmd.exe i w każdej wykonuje jeden argument. Czy jest możliwość (wiem, że w Console App jest taka możliwość poprzez StreamWriter) uruchomienia jednej instancji cmd.exe i bez jej zamykania przesyłać argumenty do wykonania po kolei??

private void button1_Click(object sender, EventArgs e)
{
    string[] Command_Array = { "/k dir", "/k cd..", "/k pause" };
    string Command;
    for (int i = 0; i <= Command_Array.Length - 1; i++)
    {
        Command = Command_Array[i];
        Process CMD = new Process();
        ProcessStartInfo PSI = new ProcessStartInfo();
        PSI.FileName = @"C:\windows\system32\cmd.exe";
        PSI.Arguments = Command;
        Process.Start(PSI);
    }
}

Dzięki, morekm

0

nie tworz tego w petli, tylko w petli przesylaj argumenty

private void button1_Click(object sender, EventArgs e)
{
    string[] Command_Array = { "/k dir", "/k cd..", "/k pause" };
    string Command;
    Process CMD = new Process();
    ProcessStartInfo PSI = new ProcessStartInfo();
    PSI.FileName = @"C:\windows\system32\cmd.exe";
    for (int i = 0; i <= Command_Array.Length - 1; i++)
    {
        Command = Command_Array[i];
        PSI.Arguments = Command;
        Process.Start(PSI);
    }
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1