71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// 외부 프로세스가 종료되었을 때 호출할 콜백 델리게이트
|
|
/// </summary>
|
|
public static event Action ExeExited;
|
|
|
|
/// <summary>
|
|
/// 외부 프로세스를 실행하고 종료 이벤트를 감지
|
|
/// </summary>
|
|
/// <param name="exePath">실행할 EXE 파일 경로 (예: .../StringReader.exe)</param>
|
|
/// <param name="argPath">선택적 인자 경로 (예: .../Pattern.msr)</param>
|
|
/// <param name="exeExited">EXE 파일 종료시, 이벤트 콜백을 받을 델리게이트 </param>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 외부 프로세스가 종료되었을 때 호출되는 이벤트 핸들러
|
|
/// </summary>
|
|
private static void OnProcessExited(object sender, EventArgs e) {
|
|
_Logger.FuncI("External process exited.");
|
|
ExeExited?.Invoke();
|
|
}
|
|
}
|
|
}
|