【问题标题】:How to quit scala 2.11.0 REPL?如何退出 scala 2.11.0 REPL?
【发布时间】:2014-04-22 23:42:38
【问题描述】:

在 scala (2.10.3) REPL 的最新版本中,我可以键入 exit 以退出 REPL。但是,在 Scala 2.11.0 中这不起作用。

$ scala
Welcome to Scala version 2.11.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> exit
<console>:8: error: not found: value exit
              exit
              ^

scala>

【问题讨论】:

    标签: scala scala-2.11


    【解决方案1】:

    我在升级时遇到了同样的问题,只需使用冒号 q。

    :q
    

    此外,exit 在 2.10.x 中已被弃用,而建议使用 sys.exit,所以这也适用:

    sys.exit
    

    作为旁注,我认为他们这样做是为了让您可以区分退出 sbt 中的 scala 控制台和退出 sbt 本身,尽管我可能是错的。

    【讨论】:

      【解决方案2】:

      如之前的答案所述,您可以选择离开 REPL:

      :quit
      :q
      
      Ctrl + d // Unix
      Ctrl + z // Windows
      
      sys.exit
      

      【讨论】:

      • 目前没有 Windows 机器可供我使用。 @GovindSinghNagarkoti 。什么对你有用?
      • @AndreasNeumann 除了ctrl+d 之外,所有其他人都为我工作,我正在使用windows 7
      • 我使用的是 Windows 10 并安装了 Cygwin:ctrl+d 有效,但 ctrl+z 无效。不确定这是否与 Cygwin 有关。
      • ctrl-c 也会退出 repl,这很烦人,因为在几乎所有其他 repl 中它都会取消当前行
      【解决方案3】:

      使用文件结尾字符。 Ctrl-D 在 Linux 上,Ctrl-Z 在 Windows 上。

      在我的 2.10.3 REPL 上使用 :help 命令得到了这个提示:

      :quit        exit the interpreter
      

      我不知道 :quit 在 2.11.0 中是否仍然存在。

      【讨论】:

      • 如果你使用 sbt,ctl-D 会让你退出任一命令提示符。这就是我在某个时候开始做的事情。 :q vs exit 事情让我发疯了。你能告诉我吗?
      • 你也可以使用java.lang.System.exit(0);
      • @ElliottFrisch 当然,我每次都想打字
      【解决方案4】:

      当我在 2.10.4 中使用 exit 时,我收到了警告:

      警告:有 1 个弃用警告;使用 -deprecation 重新运行以了解详细信息

      你可以使用:

      :q
      :quit
      sys.exit
      

      它们都在 2.11.x 中工作。

      【讨论】:

        【解决方案5】:

        你可以使用 系统退出 或者 :q 退出shell

        【讨论】:

        • 多年前,在这个问题的先前答案中已经指出了这一点。
        【解决方案6】:

        对于 sbt 1.4.1 命令使用以下命令

         exit:Terminates the remote client or the build when called from the console.
         shutdown:Terminates the build.
        

        例子

        vudikeri@C02CP3LAMD6M scala % sbt version 
        [info] welcome to sbt 1.4.1 (N/A Java 14.0.1)
        
        sbt:scala> shutdown
        [info] shutting down sbt server
        vudikeri@C02CP3LAMD6M scala % 
        
        sbt:scala> exit
        [info] shutting down sbt server
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-06-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-04-19
          • 2014-08-22
          • 1970-01-01
          相关资源
          最近更新 更多