Executing shell commands from Scala REPL

后端 未结 5 1968
礼貌的吻别
礼貌的吻别 2021-01-01 20:44

An interesting feature of Scala REPL is if you drop any jar in your %SCALA_HOME%\\lib directory, it is available for import from the REPL. I have several jars t

5条回答
  •  难免孤独
    2021-01-01 21:21

    UPDATE

    The means for extracting :sh output has changed over the years.

    Welcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_91).
    Type in expressions for evaluation. Or try :help.
    
    scala> :sh date
    res0: scala.tools.nsc.interpreter.ProcessResult = `date` (1 lines, exit 0)
    
    scala> res0 foreach println
    :13: error: value foreach is not a member of scala.tools.nsc.interpreter.ProcessResult
           res0 foreach println
                ^
    
    scala> res0.show
    :13: error: value show is not a member of scala.tools.nsc.interpreter.ProcessResult
           res0.show
                ^
    
    scala> res0.lines
    res3: List[String] = List(Sat Sep 17 19:29:26 PDT 2016)
    

提交回复
热议问题