Open
Description
Compiler version
This is common to all versions of scala3 that I've tried.
It can be demonstrated with scala3-3.6.3-x86_64-pc-win32
.
No such error occurs in scala 2.13
.
Minimized code
#!/usr/bin/env -S scala
val lines = for {
line <- scala.collection.Iterator.Iterator.continually(scala.io.StdIn.readLine()).takeWhile( _ != null )
if line != null
} yield line
printf("%d lines\n", lines.size)
Output
# ls -l | jsrc/readStdin.sc
stty: 'standard input': Inappropriate ioctl for device
Compiling project (Scala 3.6.3, JVM (17))
Compiled project (Scala 3.6.3, JVM (17))
837 lines
Expectation
No error message
A fix is to not call stty
unless there's a tty
, as in this modification of scala3-3.6.3-x86_64-pc-win32/libexec/common-shared
#!/usr/bin/env bash
#/*--------------------------------------------------------------------------
# * Credits: This script is based on the script generated by sbt-pack.
# *--------------------------------------------------------------------------*/
if [ -e /usr/bin/tty -a "`tty`" != "not a tty" -a ! -p /dev/stdin ]; then
isterminal=1
# save terminal settings
saved_stty=$(stty -g 2>/dev/null)
# clear on error so we don't later try to restore them
if [[ ! $? ]]; then
saved_stty=""
fi
else
isterminal=0
fi
# restore stty settings (echo in particular)
function restoreSttySettings() {
[ $isterminal -eq 1 ] && stty $saved_stty
saved_stty=""
}
It's also necessary to condition another call to stty
later in the file:
[ $isterminal -eq 1 ] && stty -icanon min 1 -echo
Making stty
calls conditional fixes the problem in all my manually tested environments, including cygwin
, msys64
, git-bash
, WSL ubuntu
, Linux Ubuntu
and OSX
.
I can submit a PR.