It is normal practice to open the command prompt and executecommands. The command when executed shows the result onto thescreen. There are many commands that we execute daily such as dir,find etc. C# programmers have to code in diverse satiations. Asituation may arise when you want to execute a (shell) command fromthe C# application. Don’t Worry!!! Here is the code to do so…In the code given below we create a process i.e. a command processand then invoke the command that we want to execute. The result of the command is stored in a string variable, which can then be used forfurther references. The command execution can happen in two ways,
synchronously
and
asynchronously
. In the asynchronous commandexecution we just invoke the command execution using a thread thatruns independently.
usingSystem;usingSystem.Threading; namespaceExecuteCommand{ public class Program
{ static voidMain(string[] args)
{ stringcommand =String.Empty;
// Write to the console. Console.Write("Enter the command you wish to execute: ");
// Get the command you wish to execute.command =Console.ReadLine().Trim();