Skip to content

Commit

Permalink
(consoleapp) Fix exception in mintty-based shells on Windows
Browse files Browse the repository at this point in the history
Closes #107
  • Loading branch information
perlun committed Feb 15, 2022
1 parent 44485bb commit dcb40e5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Perlang.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
using Perlang.Parser;
using ParseError = Perlang.Parser.ParseError;

#if _WINDOWS
using System.Diagnostics;
#endif

namespace Perlang.ConsoleApp
{
public class Program
Expand Down Expand Up @@ -201,7 +205,7 @@ public static int MainWithCustomConsole(string[] args, IConsole console)
replMode: true,
standardOutputHandler: console.Out.WriteLine,
disabledWarningsAsErrors: disabledWarningsAsErrorsList
).RunPrompt();
).RunPrompt(args);

return Task.FromResult(0);
}
Expand Down Expand Up @@ -328,8 +332,20 @@ private int RunFile(string path)
return (int)ExitCodes.SUCCESS;
}

private void RunPrompt()
#pragma warning disable S1172 // Remove this unused method parameter 'args'.
private void RunPrompt(string[] args)
{
#if _WINDOWS
if (Console.IsInputRedirected)
{
Console.WriteLine("Input redirection detected, relaunching with winpty");
var process = Process.Start("winpty", Environment.ProcessPath! + String.Join(' ', args));
process!.WaitForExit();

return;
}
#endif

PrintBanner();
ReadLine.HistoryEnabled = true;
ReadLine.AutoCompletionHandler = new AutoCompletionHandler();
Expand All @@ -349,6 +365,7 @@ private void RunPrompt()
Run(command, CompilerWarningAsWarning);
}
}
#pragma warning restore S1172

internal int Run(string source, CompilerWarningHandler compilerWarningHandler)
{
Expand Down

0 comments on commit dcb40e5

Please sign in to comment.