Bạn có thể viết một kịch bản Groovy bên ngoài thực hiện tất cả các lần nhập, tạo ra một đối tượng GroovyConsole và gọi phương thức run() trên đối tượng này.
cũng http://groovy.codehaus.org/Groovy+Console#GroovyConsole-EmbeddingtheConsole
Xem Ví dụ: start.groovy
import groovy.ui.Console;
import com.botkop.service.*
import com.botkop.service.groovy.*
def env = System.getenv()
def service = new ServiceWrapper(
userName:env.userName,
password:env.password,
host:env.host,
port:new Integer(env.port))
service.connect()
Console console = new Console()
console.setVariable("service", service)
console.run()
Từ một kịch bản shell gọi thực thi groovy cung cấp nó với kịch bản hấp dẫn:
#!/bin/bash
if [ $# -ne 4 ]
then
echo "usage: $0 userName password host port"
exit 10
fi
export userName=$1
export password=$2
export host=$3
export port=$4
export PATH=~/apps/groovy/bin:/usr/bin:$PATH
export CLASSPATH=$(find lib -name '*.jar' | tr '\n' ':')
groovy start.groovy
Các mã trong GroovyConsole bây giờ có thể tận dụng việc nhập khẩu được thực hiện trong start.groovy, cũng như các biến được tạo và được truyền bằng phương thức setVariable ('dịch vụ' trong examp le).