2

How might I run CMD.EXE from my C# Console Aplication? Like in Powershell you can run cmd.exe by typing "cmd"

EDIT: Open Powershell. Type "cmd". That's what I want.

EDIT2: Thank you for your help. I will try to make it clearer. I want it so that when the user enters "cmd" into my command line C# Application, it runs CMD.EXE in that same window. it is basically the same as typing CMD in Powershell.

2
  • What do you mean by "run cmd"? Start process? Open "Command line" window? Commented Dec 3, 2010 at 1:02
  • You could look into piping. Essentially you want the ouput from cmd pipend in your own shell and your shells input sent to cmd for execution. Commented Dec 3, 2010 at 1:37

2 Answers 2

4

is Process.Start("cmd.exe") is what you're seeking for? (Don't forget to add using System.Diagnostics))
More info about Process class on MSDN

Sign up to request clarification or add additional context in comments.

9 Comments

unfortunantly, there is no Process in a C# Console Application
see update) (add using directive or just use System.Diagnostics.Process.Start("cmd.exe"))
Thanks, but is there a way to open it in the same window?
I don't clearly get what you want to achieve. Do you want to redirect user's input to shell? Update the question, please, with information about your problem/idea.
What you seem to be looking for is writing your own shell. You don't need to start a "cmd.exe" for executing processes from your own commandline.
|
3

I think that you want your user to have an interactive shell inside your application.

One way to do that is to redirect both stdin and stdout of cmd.exe to your application. It will input/output data from console in a string so you can show it in a textbox of whatever flots your boat.

This project from code project seems to do what you want to do

1 Comment

Wasn't the answer I was looking for right now but very handy to know, thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.