How to wirte into the cmd from a WPF application?

  • Thread starter Thread starter ComptonAlvaro
  • Start date Start date
C

ComptonAlvaro

Guest
I am trying to open a cmd, see what I would see if I open the cmd myself and write commands in the cmd from code, from my WPF application.

I am trying something like that:

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

try { p.Start(); }
catch (Exception ex)
{
Console.WriteLine(ex);
return;
}


StreamWriter sw = p.StandardInput;
sw.WriteLine("mspaint.exe");
sw.WriteLine("cd..");
sw.Close();
p.WaitForExit();
Console.WriteLine(p.StandardOutput.ReadToEnd());


The problem is that the cmd window is empty, a blank window. I would like to she the command prompt, I mean, the path of the folder in which I am.

However, the first command is executed and microsoft paint is open. But the command mspaint.exe is not shown.

I would like to that if I send the comand, that is shown, and if I write "cd.." is shown too and I would like to see the path of the folder in the command prompt.

Is it possible to do that?



Thanks so much.

Continue reading...
 
Back
Top