Skip to content

Commit 0af45eb

Browse files
committed
spawner: Add option to pull stdout from console.
1 parent c1a9e92 commit 0af45eb

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

VisualPinball.Engine.Mpf.Test/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public static async Task Main(string[] args)
3838
var s = Stopwatch.StartNew();
3939
var mpfApi = new MpfApi(machineFolder);
4040

41-
mpfApi.Launch(new MpfConsoleOptions { ShowLogInsteadOfConsole = false });
41+
mpfApi.Launch(new MpfConsoleOptions {
42+
ShowLogInsteadOfConsole = true,
43+
CatchStdOut = true,
44+
});
4245

4346
mpfApi.StartGame(new Dictionary<string, bool> {
4447
{"sw_11", false},

VisualPinball.Engine.Mpf/MpfApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static MachineDescription GetMachineDescription(string machineFolder)
3131
{
3232
var client = new MpfClient();
3333
var spawner = new MpfSpawner(machineFolder);
34-
spawner.Spawn(new MpfConsoleOptions());
34+
spawner.Spawn(new MpfConsoleOptions { ShowLogInsteadOfConsole = true });
3535
client.Connect("localhost:50051");
3636
client.StartGame(new Dictionary<string, bool>(), false);
3737
var description = client.GetMachineDescription();

VisualPinball.Engine.Mpf/MpfSpawner.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,22 @@ private void RunMpf(string mpfExePath, MpfConsoleOptions options)
6464
FileName = mpfExePath,
6565
WorkingDirectory = _pwd,
6666
Arguments = args,
67-
UseShellExecute = true,
68-
RedirectStandardOutput = false,
69-
67+
UseShellExecute = !options.CatchStdOut,
68+
RedirectStandardOutput = options.CatchStdOut,
7069
};
7170

7271
using (var process = Process.Start(info)) {
7372
_ready.Release();
74-
process.WaitForExit();
73+
if (!options.CatchStdOut) {
74+
process.WaitForExit();
75+
76+
} else {
77+
using (var reader = process.StandardOutput) {
78+
var result = reader.ReadToEnd();
79+
Console.Write(result);
80+
process.WaitForExit();
81+
}
82+
}
7583
}
7684
}
7785

@@ -109,5 +117,6 @@ public class MpfConsoleOptions
109117
public bool UseMediaController;
110118
public bool ShowLogInsteadOfConsole;
111119
public bool VerboseLogging = true;
120+
public bool CatchStdOut;
112121
}
113122
}

0 commit comments

Comments
 (0)