Mimic batch file with c #

I have a batch file that runs four commands

vsinstr -coverage hello.exe
vsperfcmd /start:coverage /output:run.coverage
hello
vsperfcmd /shutdown

How can I use C # to run four commands?

+2
source share
3 answers

Run the commands using Process.Start .

Example

Using Override Process.Start(string fileName, string arguments)

Process.Start("vsinstr", "-coverage hello.exe");
Process.Start("vsperfcmd", "/start:coverage /output:run.coverage");
Process.Start("hello");
Process.Start("vsperfcmd", "/shutdown");
+2
source

Add this command to the batch file and use the code below to run

 ProcessStartInfo startInfo;
 System.Diagnostics.Process batchExecute;

 startInfo = new ProcessStartInfo("batchFilePath");
 startInfo.CreateNoWindow = true;
 startInfo.WindowStyle = ProcessWindowStyle.Hidden;
 startInfo.UseShellExecute = true;
 startInfo.Verb = "runas";

 batchExecute = new System.Diagnostics.Process();
 batchExecute.StartInfo = startInfo;

 batchExecute.Start();

 batchExecute.WaitForExit();
+3
source

Since you already have a batch file, why not run it from C # instead of running commands from it with C #? For example: Process.Start

0
source

Source: https://habr.com/ru/post/1791659/


All Articles