我正在使用C#在Windows App上工作。单击该按钮以打开.bat文件并运行该脚本。当我这样做时:
var proc = Process.Start(@"filelocation.bat");
proc.WaitForExit();
它对我不起作用。当我从文件夹中单击脚本工作正常。从按钮单击它打开几秒钟并关闭窗口。
答案 0 :(得分:-1)
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();
}