Skip to content

Commit a802f7f

Browse files
committed
Fix: setup console for non-REPL mode
1 parent 0a17b6a commit a802f7f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ protected void launch(Builder contextBuilder) {
505505

506506
if (commandString != null || inputFile != null) {
507507
try {
508-
evalNonInteractive(context);
508+
evalNonInteractive(context, consoleHandler);
509509
rc = 0;
510510
} catch (PolyglotException e) {
511511
if (!e.isExit()) {
@@ -590,7 +590,11 @@ private static void printPythonLikeStackTrace(PolyglotException e) {
590590
System.err.println(e.getMessage());
591591
}
592592

593-
private void evalNonInteractive(Context context) throws IOException {
593+
private void evalNonInteractive(Context context, ConsoleHandler consoleHandler) throws IOException {
594+
// We need to setup the terminal even when not running the REPL because code may request
595+
// input from the terminal.
596+
setupTerminal(consoleHandler);
597+
594598
Source src;
595599
if (commandString != null) {
596600
src = Source.newBuilder(getLanguageId(), commandString, "<string>").build();
@@ -855,6 +859,14 @@ private void setupREPL(Context context, ConsoleHandler consoleHandler) {
855859

856860
}
857861

862+
private void setupTerminal(ConsoleHandler consoleHandler) {
863+
consoleHandler.setupReader(() -> false, () -> 0, (item) -> {
864+
}, (pos) -> null, (pos, item) -> {
865+
}, (pos) -> {
866+
}, () -> {
867+
}, null);
868+
}
869+
858870
/**
859871
* Some system properties have already been read at this point, so to change them, we just
860872
* re-execute the process with the additional options.

0 commit comments

Comments
 (0)