进程结束等待退出
问题描述:
我正在使用C#开发Windows应用程序。按钮点击打开.bat文件并运行脚本。当我这样做:进程结束等待退出
var proc = Process.Start(@"filelocation.bat");
proc.WaitForExit();
它不适合我。当我点击该文件夹中的脚本时工作正常。从按钮单击它将打开几秒钟并关闭窗口。
答
This following one worked for me!
using System.Diagnostics;
public void ExecuteBatFile()
{
Process proc = null;
string _batDir = string.Format(@"C:\"); //File path Location
proc = new Process();
proc.StartInfo.WorkingDirectory = _batDir;
proc.StartInfo.FileName = "myfile.bat"; // Batch File name
proc.Start();
proc.WaitForExit();
proc.Close();
}
然后,它听起来像你的心不是应用的思考当前目录是该filelocation.bat是..... – BugFinder
我也试图在C#项目移到整个脚本文件夹 - 资源文件夹。然后在按钮点击中引用该路径 - 相同的结果。它打开个性,但从应用程序关闭。如何让应用程序知道当前目录? – Salah
阅读流程类 - 它有很多选项,其中之一就是它的起点 – BugFinder