如何将此 Perl 代码转换为 Groovy?
如何绕过外部进程的确认提示?
我正在尝试将 Perl 脚本转换为 Groovy。该程序正在自动加载/删除 maestro(作业调度)作业。问题是删除命令将提示它找到的每个作业的确认(Y/N)。我尝试在 groovy 中执行该过程,但会在提示符处停止。Perl 脚本正在将一堆 Y 写入流并将其打印到处理程序(如果我理解正确的话)以避免停止。我想知道如何在 Groovy 中做同样的事情?
或任何其他执行命令并以某种方式在每个确认提示上写 Y 的方法。
Perl 脚本:
$maestrostring="";
while ($x < 1500) {
$maestrostring .= "y\n";
$x++;
}
# delete the jobs
open(MAESTRO_CMD, "|ssh mserver /bin/composer delete job=pserver#APPA@")
print MAESTRO_CMD $maestrostring;
close(MAESTRO_CMD);
这是我的工作常规代码:
def deleteMaestroJobs (){
...
def commandSched ="ssh $maestro_server /bin/composer delete sched=$primary_server#$app_acronym$app_level@"
def commandJobs ="ssh $maestro_server /bin/composer delete job=$primary_server#$app_acronym$app_level@"
try {
executeCommand commandJobs
}
catch (Exception ex ){
throw new Exception("Error executing the Maestro Composer [DELETE]")
}
try {
executeCommand commandSched
}
catch (Exception ex ){
throw new Exception("Error executing the Maestro Composer [DELETE]")
}
}
def executeCommand(command){
def process = command.execute()
process.withWriter { writer ->
writer.print('y\n' * 1500)
}
process.consumeProcessOutput(System.out, System.err)
process.waitFor()
}