Issue1987

classification
Title: System.console().readLine only reads a single character
Type: Severity: normal
Components: Core Versions: Jython 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: JoshDavisNC, amak, fwierzbicki, zyasoft
Priority: Keywords: console

Created on 2012-11-14.23:44:17 by JoshDavisNC, last changed 2014-06-17.22:45:13 by zyasoft.

Messages
msg7521 (view) Author: Josh Davis (JoshDavisNC) Date: 2012-11-14.23:50:37
I have a Jython script that calls into some Java classes.  One of these classes asks the user for a username and password using the java.lang.System.console().readLine() and .readPassword() API's.  When this class is used in a Java environment without Jython, those API's work correctly.  In my Jython environment, these API's only read a single character.  I can duplicate this behavior in the interactive console like this:

>>> from java.lang import System
>>> username = System.console().readLine("Username: ")
Username: >>>
>>> username
u'j'
>>> password = System.console().readPassword("Password: ")
Password: >>>
>>> password
array('c', 'p')
msg7522 (view) Author: Josh Davis (JoshDavisNC) Date: 2012-11-14.23:53:26
I have duplicated this with Jython 2.5.2 / JRocket 1.6.0_29 in a Linux environment, and with Jython 2.5.3 / Java 1.7.0_07 in a Windows environment.
msg7705 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-19.23:06:42
Hi Josh, we have reason to believe this may be due to making JLine the default. A workaround is to use the InteractiveConsole (we are considering putting this back to the default) See here for the syntax: http://stackoverflow.com/questions/1118238/how-to-deactivate-jline-for-jython-interactive-interpreter-session
msg7893 (view) Author: Alan Kennedy (amak) Date: 2013-03-01.21:37:32
Here's a bug report from scala, which appears to exhibit the same behaviour (they compare the behaviour to jython).

https://issues.scala-lang.org/browse/SI-3442

They also assert that it happens with jruby as well.
msg8489 (view) Author: Jim Baker (zyasoft) Date: 2014-05-21.22:13:22
This does not appear to be something resolvable by upgrading to JLine2 #2092, instead we are seeing dueling interaction between our user friendly console based on JLine and the usual System.console.

Under no circumstance would I want org.python.util.InteractiveConsole (which wraps System.console) to become the default ;) See below for why:

Instead, users with this sitation can simply use the workaround Frank linked:

$ jython27 -Dpython.console=org.python.util.InteractiveConsole
console: Failed to install 'org.python.util.InteractiveConsole': does not implement interface org.python.core.Console.
Jython 2.7b3+ (default:06161ebf74ee+, May 21 2014, 12:09:01)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_21
Type "help", "copyright", "credits" or "license" for more information.
>>> ^[[B^[[A^[[A^[[A^[[A^[[A^[[A
>>> # where's my history?!!!!
>>> from java.lang import System
>>> username = System.console().readLine("Username: ")
Username: foobar
>>> username
u'foobar'

It might be nice to remove that scary message however.
History
Date User Action Args
2014-06-17 22:45:13zyasoftsetstatus: pending -> closed
2014-05-21 22:13:23zyasoftsetstatus: open -> pending
resolution: wont fix
messages: + msg8489
nosy: + zyasoft
2013-03-01 21:37:32amaksetmessages: + msg7893
2013-02-25 21:59:06amaksetnosy: + amak
2013-02-25 21:58:03amaksetkeywords: + console
2013-02-19 23:06:42fwierzbickisetnosy: + fwierzbicki
messages: + msg7705
versions: + Jython 2.5, - 2.5.3b2
2012-11-14 23:53:27JoshDavisNCsetmessages: + msg7522
2012-11-14 23:50:37JoshDavisNCsetmessages: + msg7521
2012-11-14 23:44:17JoshDavisNCcreate