为什么Groovy执行()挂起?

时间:2013-07-01 00:17:07

标签: scala groovy

我有以下Groovy脚本:

#!/opt/groovy-1.8.6/bin/groovy

final env = null // []

final command = ["./setter-for-catan.scala"]
final process = command.execute(env, null)

println (['echo', '********************** 0'].execute(env, null).text)
final stdout = process.inputStream
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout))
while ((line = reader.readLine()) != null) {
    System.out.println ("Stdout: " + line);
}

以及以下Scala脚本:

#!/bin/bash

export SCALA_HOME=/opt/scala-2.10.1

echo '********************* 1' "$0" "$@"
${SCALA_HOME}/bin/scala -version 2>&1
exec ${SCALA_HOME}/bin/scala "$0" "$@" 2>&1
!#

println("******************* 2")

调用Groovy脚本输出:

********************** 0

Stdout: ********************* 1 ./setter-for-catan.scala
Stdout: Scala code runner version 2.10.1 -- Copyright 2002-2013, LAMP/EPFL
Stdout: ******************* 2

如果env定义为[],则Groovy脚本会挂起以下输出:

********************** 0

Stdout: ********************* 1 ./setter-for-catan.scala
Stdout: Scala code runner version 2.10.1 -- Copyright 2002-2013, LAMP/EPFL

execute()env时,Array没有挂起,发生了什么以及需要做什么?

1 个答案:

答案 0 :(得分:1)

Scala脚本没有继承JAVA_HOME,因此需要对其进行定义。

执行此操作的一种方法是使用Scala脚本:

#!/bin/bash

export JAVA_HOME=/Library/Java/Home
export SCALA_HOME=/opt/scala-2.10.1

echo '********************* 1' "$0" "$@"
${SCALA_HOME}/bin/scala -version 2>&1
exec ${SCALA_HOME}/bin/scala "$0" "$@" 2>&1
!#

另一种方法是在Groovy脚本中执行此操作:

final env = ['JAVA_HOME=/Library/Java/Home']