English 中文(简体)
Groovy:控制shell进程I/O提示
原标题:Groovy: controlling a shell processes I/O prompts

在groovy中,我需要运行一个我没有编写的shell命令。此命令提示用户输入各种输入值。因此,我试图弄清楚如何响应来自groovy脚本的提示。到目前为止,我已经:

Process proc = command.execute()
parms.each() {value -> 
    proc << String.valueOf(value) + "
"
}
StringBuilder output = new StringBuilder()
proc.waitForProcessOutput(output, output)
return output.toString()

这在启动命令并将parm传递给它时起作用,但所有parm都传递给命令的第一个提示符。

我是groovy的新手,所以我很难弄清楚如何处理这个问题。理想情况下,我希望能够拾取每个提示并给出匹配的答复,而不是这种对提示顺序做出脆弱假设的方法。

以前有人用groovy做过这样的事情吗?

问题回答

您可以尝试使用expectj,它是预期

(不是专门针对groovy的,但值得一看)

HTH





相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签