简体   繁体   中英

Run CMD from C# Console Application?

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM