Right now I'm calling an external bash script via open, because said script might run for seconds or it might run for minutes. The only things that are certain are:
- It will output text which has to be displayed to the user. Not after the script is done, but while it is still running.
- It will set a return code with different meanings
Reading and using the text outputted by the shell script does work. But I don't have a clue on how to read the return code.
The (simplified) TCL script looks like this:
#!/usr/bin/tclsh
proc run_script {} {
set script "./testing.sh"
set process [open "|${script}" "r"]
chan configure $process -blocking 0 -translation {"lf" "lf"} -encoding "iso8859-1"
while {[eof $process] == 0} {
if {[gets $process zeile] != -1} {
puts $zeile
}
update
}
close $process
return "???"
}
set rc [run_script]
puts "RC = ${rc}"
The (simplified) shell script does look like this:
#!/bin/bash
echo Here
sleep 1
echo be
sleep 2
echo dragons
sleep 4
echo ....
sleep 8
exit 20
So how do I read the return code of the shell script via tcl?