Mimic batch file with C#
I have a batch file that runs the four commands
vsinstr -coverage hello.exe
vsperfcmd /start:coverage /output:run.coverage
hello
vsperfcmd /shutdown
How can I 开发者_Python百科use C# to run the four commands?
Add these command to a batch file and use the below code to run it
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();
Run the commands using Process.Start.
Example
Using the 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");
Since you already have a batch file, why not run it from C# instead of running the commands in it from C#? For example:Process.Start
精彩评论