Cygwin:Scala解释器在后台运行时突然退出

时间:2017-03-17 13:24:16

标签: bash scala shell cygwin

考虑以下shell函数:

run_in_background() {
  type scala
  java -version
  /cygdrive/c/Development/Software/scala-2.12.0/bin/scala -version
    scala -version
}

命令:run_in_background

输出:

Kshitiz.Sharma /cygdrive/c/Development/temp
$ run_in_background
scala is hashed (/cygdrive/c/Development/Software/scala-2.12.0/bin/scala)
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
Scala code runner version 2.12.0 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.
Scala code runner version 2.12.0 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

命令:run_in_background &

输出:

Kshitiz.Sharma /cygdrive/c/Development/temp
$ run_in_background  &
[7] 12712
scala is hashed (/cygdrive/c/Development/Software/scala-2.12.0/bin/scala)

Kshitiz.Sharma /cygdrive/c/Development/temp
$ java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)


[7]+  Stopped                 run_in_background

我真的不知道为什么会这样。如果scala解释器在后台运行,为什么要关心呢?为什么它会突然退出?

我在Cygwin上使用bash

2 个答案:

答案 0 :(得分:1)

对路径的支持是不一致的,即在Cygwin下没有正确解释某些路径,并且它有点像命中注定。尝试使用cygpath使您的路径与Windows兼容。 另外:我对Cygwin发行版的Babun有很好的体验。和你一样,我在Windows上开发Scala。你可能想尝试一下。

if [ "$(expr substr $(uname -s) 1 6)" == "CYGWIN" ];then
    echo "Detected CYGWIN environment"
    #If running in cygwin then ensure paths are windows compatible
    SBT_LAUNCHER="`cygpath -w $SBT_LAUNCHER`"
fi

答案 1 :(得分:1)

感谢@radumanolescu指出我正确的方向。

Scala附带两组脚本,一组用于Linux,另一组用于Windows。当您在Cygwin窗口中键入scala时,它将执行Linux脚本。

Cygwin没有100%的兼容性,并且不能总是成功运行这些脚本,这是其中一种情况。

修复是使用Windows批处理文件而不是linux shell脚本。将此添加到bash配置文件中:

scala() {
    scala.bat "$@"
}; export -f scala

export -f导出该函数,以便它可用于任何子shell。