简体   繁体   中英

Execute .exe and parameters through C# and cmd command

Although there are some explanations regarding my problem, I can't solve the following cmd command issue. My goal is to start an .exe with some parameters through C#, which has to manipulate more than one file in a row. Even if I wait until the process has finished, it does not end. Without waiting for the end (Process.WaitForExit()), it looks like the different commands are terminating each other without execution. How can I achieve, with the following method, execution of each .exe file I want to?

ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = false;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = @"\c Path_of_the_exe " + Path_of_the_file;

using (Process exeProcess = Process.Start(startInfo))
{
   exeProcess.WaitForExit();
}

I can't think of any reason why you would need to use cmd.exe to launch an exe. You can just launch your exe directly:

ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = false;
startInfo.FileName = Path_of_the_exe;
startInfo.Arguments = Path_of_the_file;

using (Process exeProcess = Process.Start(startInfo))
{
   exeProcess.WaitForExit();
}

Launching cmd.exe like you are may explain the behaviour you are experiencing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM