Hi folks,
I have to execute a ksh-script in jacl and
react if this ksh-script exits with errors.
Additionally I need the output of the script on the screen (stdout).
So I did the following (I replaced my script with a simple 'hostname'
command)
========================
set status 0
if {[catch {exec hostname} results]} {
if {[lindex $::errorCode 0] == "CHILDSTATUS"} {
set status [lindex $::errorCode 2]
puts "Script exits with Errorcode $status"
} else {
puts "Script exits with unexpected error"
}
}
========================
However, then you can't see any output of 'exec hostname'.
Even if I put a 'puts' around the exec, I can see the output if everything works ok,
but not if something goes wrong (try to replace the hostname with 'blabla':
========================
set status 0
if {[catch {puts [exec blabla]} results]} {
if {[lindex $::errorCode 0] == "CHILDSTATUS"} {
set status [lindex $::errorCode 2]
puts "Script exits with Errorcode $status"
} else {
puts "Script exits with unexpected error"
}
}
========================
Any ideas or workarounds to catch the exec and see the output of it even if the script fails?
thanks and best regards,
Johannes Kleinlercher
|