Chris
Chris

Reputation: 1900

Can't Get Command to Execute in Console App

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.

Upvotes: 0

Views: 221

Answers (1)

qxg
qxg

Reputation: 7036

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

Upvotes: 5

Related Questions