0

我有以下 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()不挂起?envArray

4

1 回答 1

1

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

一种方法是在 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']
于 2013-07-01T03:27:47.507 回答