private void RunMpf(string mpfExePath, MpfConsoleOptions options)
        {
            var args = $"\"{_machineFolder}\"";

            if (options.UseMediaController)
            {
                args = "both " + args;
            }
            else
            {
                args += " -b";
            }

            if (options.ShowLogInsteadOfConsole)
            {
                args += " -t";
            }
            if (options.VerboseLogging)
            {
                args += " -v -V";
            }
            var info = new ProcessStartInfo {
                FileName               = mpfExePath,
                WorkingDirectory       = _pwd,
                Arguments              = args,
                UseShellExecute        = !options.CatchStdOut,
                RedirectStandardOutput = options.CatchStdOut,
            };

            Logger.Info($"[MPF] Spawning: > {mpfExePath} {args}");

            using (var process = Process.Start(info)) {
                _ready.Release();
                if (!options.CatchStdOut)
                {
                    process.WaitForExit();
                }
                else
                {
                    using (var reader = process.StandardOutput) {
                        var result = reader.ReadToEnd();
                        Console.Write(result);
                        process.WaitForExit();
                    }
                }
            }
        }
        public void Spawn(MpfConsoleOptions options)
        {
            var mpfExe     = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "mpf.exe" : "mpf";
            var mpfExePath = GetFullPath(mpfExe);

            if (mpfExePath == null)
            {
                throw new InvalidOperationException($"Could not find {mpfExe}!");
            }

            _thread = new Thread(() => {
                Thread.CurrentThread.IsBackground = true;
                RunMpf(mpfExePath, options);
            });

            _thread.Start();
            _ready.Wait();
        }
 /// <summary>
 /// Launches MPF in the background and connects to it via gRPC.
 /// </summary>
 /// <param name="options">MPF options</param>
 /// <param name="port">gRPC port to use for MPC/VPE communication</param>
 /// <returns></returns>
 public void Launch(MpfConsoleOptions options, int port = 50051)
 {
     _spawner.Spawn(options);
     Client.Connect($"localhost:{port}");
 }