0

I'm writing a small test application. I'm trying to run the command prompt through a C# console app, but I can't get it to work.

Everything I've researched says I am doing it correctly.

Here is the code:

class Program
{
   static void Main( string[ ] args )
   {
       Process.Start( "cmd", "echo testing" );
       Console.ReadKey( );
   }
}

When it runs, the cmd window appears, but "testing" is never written.

Chris
  • 1,690
  • 2
  • 17
  • 24
  • How do you run the program? Where do you expect "testing" to be written? – Code-Apprentice May 04 '18 at 03:29
  • You need to pipe the stdout of the process to the stdout of the c# app. check out https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output – AJ X. May 04 '18 at 03:30

1 Answers1

5
Process.Start( "cmd", "/k echo testing" );

See cmd's help by cmd /?

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string]

/C Carries out the command specified by string and then terminates

/K Carries out the command specified by string but remains

qxg
  • 6,955
  • 1
  • 28
  • 36