Using the Command Prompt in C# Win App
-
Hello, I am writing a C# windows application. I would like to open a command prompt and execute a few lines of code. I am able to open the command prompt using the following code: System.Diagnostics.Process.Start("cmd.exe"); But I don't know how to actually write a command to the prompt once it is open. Can anyone help me out? Thanks, RC
-
Hello, I am writing a C# windows application. I would like to open a command prompt and execute a few lines of code. I am able to open the command prompt using the following code: System.Diagnostics.Process.Start("cmd.exe"); But I don't know how to actually write a command to the prompt once it is open. Can anyone help me out? Thanks, RC
If you read the documentation for the
Process.Start
method, the following should be evident:Process.Start("cmd.exe", "/c someapp.exe");
Other documentation for members of the
Process
class show examples of how to capture console output. Please note that if an application uses the console subsystem, you don't actually need to start cmd.exe (the command environment for Windows NT - command.com for Windows (9x/ME)). A console program in Windows NT (NT4, 2000, XP, and 2003, plus all future Windows platforms) will automatically start in a console window, which you can suppress by using theProcess.Start(ProcessStartInfo)
method override and setProcessStartInfo.CreateNoWindow
totrue
. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles]