How to run command prompt from visual studio

|
| By Webner

Command prompt can be called from the visual studio. Commands that are used to run it from the visual studio are listed below:

Step 1: Firstly we will create an object for processstartinfo like this-
ProcessStartInfo pro = new ProcessStartInfo();

Step 2: Then file name needs to be passed which we want to run
pro.FileName = "cmd.exe"

Step 3: Then working directory needs to be defined:
pro.WorkingDirectory = @"C:\AL3Parser-1.11";

Step 4: Then we give arguments. Basically, arguments specify the command which we want to run
pro.Arguments = " /c" + Command;

Step 5: Then we will create a new process by creating the object of the process
Process proStart = new Process();

Step 6: Next step will look like this
proStart.StartInfo = pro;

Step 7: Then we will give the command to start the process.
proStart.Start();

By following the above steps we can run the command prompt application from the visual studio when required.
Also, if we want to run the application in the background only i.e. we want that the screen should not be visible while running the project only commands should run then one command can be given:

pro.WindowStyle = ProcessWindowStyle.Hidden;

This is how we can implement this in our function:

And also if we want that command prompt should not get pop in the execution, only in the background we want our commands to run then we can use one more command i.e:
pro.windowstyle= processWindowstyle.Hidden;

In this way, the execution command prompt will run the commands only in the background.

Leave a Reply

Your email address will not be published. Required fields are marked *