Scala Stdin.readLine() does not seem to work as expected

Omar A

I am trying to write a simple console client application where i can present some options to the user, get their input and act accordingly. If i run the code through intellij or paste it into the scala console, it works. If i run it through sbt (which is how i really need it to run), i run into all sorts of problems.

I have sbt version 0.13.8, OS is Mac, my build.sbt contains:

scalaVersion := "2.11.6"
fork in run := true

EDIT I started with the minimum scala activator template in case that is useful info in this context

I have simplified the code to barebones,

import scala.io.StdIn._

object TestClient {
  def main(args: Array[String]): Unit = {
    join()
  }

  def join(): Unit = {
    val name = readLine(s"Enter your name.${System.getProperty("line.separator")}")
    name match {
      case n: String => println(n)
      case o => {
        println(s"invalid name ${o}")
        join()
      };
    }
  }
}

When go into sbt and from the prompt enter run. one of the following seems to happen

1) I get this exception as soon as i run

Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:3332)
        at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
        at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
        at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:569)
        at java.lang.StringBuffer.append(StringBuffer.java:369)
        at java.io.BufferedReader.readLine(BufferedReader.java:370)
        at java.io.BufferedReader.readLine(BufferedReader.java:389)
        at sbt.BasicIO$$anonfun$processFully$1$$anonfun$apply$8.apply(ProcessImpl.scala:58)
        at sbt.BasicIO$$anonfun$processFully$1$$anonfun$apply$8.apply(ProcessImpl.scala:58)
        at sbt.BasicIO$.readFully$1(ProcessImpl.scala:63)
        at sbt.BasicIO$.processLinesFully(ProcessImpl.scala:69)
        at sbt.BasicIO$$anonfun$processFully$1.apply(ProcessImpl.scala:58)
        at sbt.BasicIO$$anonfun$processFully$1.apply(ProcessImpl.scala:55)
        at sbt.SimpleProcessBuilder$$anonfun$3.apply$mcV$sp(ProcessImpl.scala:354)
        at sbt.Spawn$$anon$3.run(ProcessImpl.scala:17)

2) No memory issues, but getting these messages in an infinite loop, so the readline does not seem to be waiting for any input

background log: info: Enter your name.
background log: info: invalid name null
background log: info: Enter your name.
background log: info: invalid name null
...

Either way I am unable to actually enter any input in the console. Not sure what I'm missing or doing wrong

kiritsuku

Put

connectInput in run := true

in your build.sbt. See the official docs for more info on how to correctly handle forks in sbt.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Why NodeJS KeepAlive does not seem to work as expected?

分類Dev

iOS animation presentationLayer hitTest does not seem to work as expected

分類Dev

setLocation on a JButton doesn't seem to work as expected

分類Dev

Flyway does not seem to recognize java/scala migrations

分類Dev

Guava cache 'expireAfterWrite' does not seem to always work

分類Dev

Kubernetes cluster autoscaler does not seem to work on GKE?

分類Dev

jQuery.each does not seem to work

分類Dev

My login page does not seem to work at all

分類Dev

COLLATE in UDF does not work as expected

分類Dev

COLLATE in UDF does not work as expected

分類Dev

MongoDB elemMatch does not work expected

分類Dev

JQuery slideDown does not work as expected

分類Dev

ScalaのStdIn.readLineでの奇妙な動作?

分類Dev

My first angular app does not work as expected

分類Dev

boost spirit distinct keyword does not work as expected

分類Dev

C++ Polymorphism does not work as expected

分類Dev

Object.assign recursive does not work as expected

分類Dev

DynamoDB Between query on GSI does not work as expected

分類Dev

Top and bottom layout does not work as expected

分類Dev

A regex pattern '{.*}' does not work in Vim as (I) expected

分類Dev

MySQL IF(NULL != "", 1, 0) does not work as expected

分類Dev

scala.io.StdIn.readLine()はブロッキング呼び出しですか?

分類Dev

Extended execution does not seem to work in Windows 10 Universal JavaScript apps

分類Dev

Using replace in T-SQL where condition does not seem to work

分類Dev

msbuild PackageReference.PrivateAssets = All does not seem to work

分類Dev

Using a for loop to assign methods to the valueChanged signals of QScrollbars does not seem to work

分類Dev

grid-area does not seem to work with the attr function, is this by design?

分類Dev

CanvasRenderingContext2D.fill() does not seem to work

分類Dev

My use of Scipy curve_fit does not seem to work well

Related 関連記事

  1. 1

    Why NodeJS KeepAlive does not seem to work as expected?

  2. 2

    iOS animation presentationLayer hitTest does not seem to work as expected

  3. 3

    setLocation on a JButton doesn't seem to work as expected

  4. 4

    Flyway does not seem to recognize java/scala migrations

  5. 5

    Guava cache 'expireAfterWrite' does not seem to always work

  6. 6

    Kubernetes cluster autoscaler does not seem to work on GKE?

  7. 7

    jQuery.each does not seem to work

  8. 8

    My login page does not seem to work at all

  9. 9

    COLLATE in UDF does not work as expected

  10. 10

    COLLATE in UDF does not work as expected

  11. 11

    MongoDB elemMatch does not work expected

  12. 12

    JQuery slideDown does not work as expected

  13. 13

    ScalaのStdIn.readLineでの奇妙な動作?

  14. 14

    My first angular app does not work as expected

  15. 15

    boost spirit distinct keyword does not work as expected

  16. 16

    C++ Polymorphism does not work as expected

  17. 17

    Object.assign recursive does not work as expected

  18. 18

    DynamoDB Between query on GSI does not work as expected

  19. 19

    Top and bottom layout does not work as expected

  20. 20

    A regex pattern '{.*}' does not work in Vim as (I) expected

  21. 21

    MySQL IF(NULL != "", 1, 0) does not work as expected

  22. 22

    scala.io.StdIn.readLine()はブロッキング呼び出しですか?

  23. 23

    Extended execution does not seem to work in Windows 10 Universal JavaScript apps

  24. 24

    Using replace in T-SQL where condition does not seem to work

  25. 25

    msbuild PackageReference.PrivateAssets = All does not seem to work

  26. 26

    Using a for loop to assign methods to the valueChanged signals of QScrollbars does not seem to work

  27. 27

    grid-area does not seem to work with the attr function, is this by design?

  28. 28

    CanvasRenderingContext2D.fill() does not seem to work

  29. 29

    My use of Scipy curve_fit does not seem to work well

ホットタグ

アーカイブ