Skip to content

Commit 4bdb27e

Browse files
committed
Fix console redirection for CLI operation
1 parent f9957df commit 4bdb27e

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

SharpTune/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2222
using System.Text;
2323
using EcuMapTools;
2424
using SharpTuneCore;
25+
using System.Runtime.InteropServices;
2526

2627
namespace SharpTune
2728
{
2829
public static class Program
2930
{
31+
// defines for commandline output
32+
[DllImport("kernel32.dll")]
33+
static extern bool AttachConsole(int dwProcessId);
34+
private const int ATTACH_PARENT_PROCESS = -1;
35+
3036
private static SharpTuner sharpTuner;
3137
/// <summary>
3238
/// Entry point. Runs the utility with or without exception handling, depending on whether a debugger is attached.
@@ -45,6 +51,9 @@ public static int Main(string[] args)
4551
{
4652
try
4753
{
54+
// redirect console output to parent process;
55+
// must be before any calls to Console.WriteLine()
56+
AttachConsole(ATTACH_PARENT_PROCESS);
4857
result = Run(args);
4958
}
5059
catch (Exception exception)

0 commit comments

Comments
 (0)