Write in the "Command Line" by C#

Question:

Well, I have a program, which uses the Command Line, but I can only make it write "one line", and I needed you to type more than one without erasing what was already written…

What I have so far:

CODE

 private void button3_Click(object sender, EventArgs e)
    {
        using (System.Diagnostics.Process processo = new System.Diagnostics.Process())
        {
            processo.StartInfo.FileName = Environment.GetEnvironmentVariable("comspec");
            processo.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            processo.StartInfo.Arguments = string.Format("/K IPCONFIG");
            processo.StartInfo.Arguments = string.Format("/K OPENSSL");

            processo.Start();
            processo.WaitForExit();
        }
    }

Thanks.

Answer:

Use a StreamWriter to send multiple commands in sequence:

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

    p.StartInfo = info;
    p.Start();

    using (StreamWriter sw = p.StandardInput)
    {
        if (sw.BaseStream.CanWrite)
        {
            sw.WriteLine("IPCONFIG");
            sw.WriteLine("OPENSSL");
        }
    }

Source: https://stackoverflow.com/questions/437419/execute-multiple-command-lines-with-the-same-process-using-net

Scroll to Top
AllEscort