using Aurora.Api;
using System;
using System.Diagnostics;
using System.IO;
namespace VisionCommon {
public class ExternalProcessor {
private static Logger _Logger = new Logger(typeof(ExternalProcessor).Name);
private static Process _Process;
///
/// 외부 프로세스가 종료되었을 때 호출할 콜백 델리게이트
///
public static event Action ExeExited;
///
/// 외부 프로세스를 실행하고 종료 이벤트를 감지
///
/// 실행할 EXE 파일 경로 (예: .../StringReader.exe)
/// 선택적 인자 경로 (예: .../Pattern.msr)
/// EXE 파일 종료시, 이벤트 콜백을 받을 델리게이트
public static void StartExternalProcess(string exePath, string argPath = null, Action exeExited = null) {
try {
if (!File.Exists(exePath)) {
_Logger.FuncE($"Path Error : {exePath}");
return;
}
if (exeExited != null) {
ExeExited = exeExited;
}
ProcessStartInfo psi;
if (!string.IsNullOrWhiteSpace(argPath) && File.Exists(argPath)) {
psi = new ProcessStartInfo {
FileName = exePath,
Arguments = $"\"{argPath}\"",
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Normal
};
}
else {
psi = new ProcessStartInfo {
FileName = exePath,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Normal
};
}
_Process = new Process {
StartInfo = psi,
EnableRaisingEvents = true
};
_Process.Exited += OnProcessExited;
_Process.Start();
}
catch (Exception e) {
_Logger.FuncE(e.Message);
}
}
///
/// 외부 프로세스가 종료되었을 때 호출되는 이벤트 핸들러
///
private static void OnProcessExited(object sender, EventArgs e) {
_Logger.FuncI("External process exited.");
ExeExited?.Invoke();
}
}
}