c# - 通过C#和cmd命令执行.exe和参数
问题描述
尽管对我的问题有一些解释,但我无法解决以下 cmd 命令问题。我的目标是通过 C# 启动一个带有一些参数的 .exe,它必须连续操作多个文件。即使我等到过程完成,它也不会结束。不等待结束(Process.WaitForExit()),看起来不同的命令在没有执行的情况下相互终止。如何通过以下方法实现我想要的每个 .exe 文件的执行?
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();
}
解决方案
我想不出您需要使用 cmd.exe 来启动 exe 的任何原因。您可以直接启动您的 exe:
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();
}
像您一样启动 cmd.exe 可能会解释您遇到的行为
推荐阅读
- css - 字体仅适用于英文字母?
- android - 无法在 WebView 中登录社交媒体网站
- jmeter - 我无法运行 Jmeter 脚本
- node.js - localhost(127.0.0.1)和节点Web服务器上的远程服务器ip有什么不同
- android - 难以使用矢量绘图创建自定义形状
- php - 动态输入未记录在数组 PHP 中
- windows-10 - 带有重定向到 HTML 的 Wifi 热点
- json - ReactJS 使用 JSON Schema 验证 JSON 对象
- python - 多个 Csv 到 json,没有重复的子元素
- ios - 如何根据同一节 Swift 4 中的数组更改 UITableViewCell 颜色