Bypassing confirmation prompt of an external process
Posted
by
Alidad
on Stack Overflow
See other posts from Stack Overflow
or by Alidad
Published on 2011-11-23T16:46:11Z
Indexed on
2011/11/23
17:51 UTC
Read the original article
Hit count: 416
How can I convert this Perl code to Groovy?
How to bypass confirmation prompts of an external process?
I am trying to convert a Perl script to Groovy. The program is loading/delete maestro (job scheduling) jobs automatically. The problem is the delete command will prompt for confirmation (Y/N) on every single job that it finds. I tried the process execute in groovy but will stop at the prompts. The Perl script is writing bunch of Ys to the stream and print it to the handler( if I understood it correctly) to avoid stopping. I am wondering how to do the same thing in Groovy ?
Or any other approach to execute a command and somehow write Y on every confirmation prompt.
Perl Script:
$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);
This is my groovy code so far:
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 ->
1500.times {writer.println 'Y' }
}
process.consumeProcessOutput(System.out, System.err)
process.waitFor()
}
© Stack Overflow or respective owner