Write in the "Command Line" by C #

3

Good, I have a program that uses the command line, but I can only get it to write "one line", and I needed it to write more than one without deleting 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();
        }
    }

Thank you.

    
asked by anonymous 06.10.2015 / 15:37

2 answers

1

Use 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: link

    
14.10.2015 / 02:36
0

Maybe if you change your code:

processo.StartInfo.Arguments = string.Format("/K IPCONFIG");
processo.StartInfo.Arguments = string.Format("/K OPENSSL");

by this:

processo.StartInfo.Arguments = string.Format("/K IPCONFIG & /K OPENSSL");

Can solve your problem.

    
07.10.2015 / 21:35