问题
I need help in trying to execute an executable from my C# application.
Suppose the path is cPath
, the EXE is HHTCtrlp.exe
and the parameter that has to be passed is cParams
.
How would I go about this?
The reason why the path is a variable is that there are 3 different EXE files to run and the path will change depending on which one will run, same with the parameter string.
Any help would be greatly appreciated.
回答1:
To start the process with parameters, you can use following code:
string filename = Path.Combine(cPath,"HHTCtrlp.exe");
var proc = System.Diagnostics.Process.Start(filename, cParams);
To kill/exit the program again, you can use following code:
proc.CloseMainWindow();
proc.Close();
回答2:
System.Diagnostics.Process.Start("PATH to exe", "Command Line Arguments");
回答3:
ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat(cPath, "\\", "HHTCtrlp.exe"));
startInfo.Arguments =cParams;
startInfo.UseShellExecute = false;
System.Diagnostics.Process.Start(startInfo);
来源:https://stackoverflow.com/questions/59596463/c-sharp-run-exe-with-custom-parameters