Reputation: 27
I am attempting to launch a compiled code to handle the extensive computing needed by a TCL script I am writing. When I launch the code, I am using:
if {[catch {exec $cwd/TaubinSmoother &} error_out]} {
if {[string first "couldn" $error_out] != -1} {
puts "TaubinSmoother software could not be located."
exit
} else {
puts "$error_out"
}
}
When the exec
command executes, there appears to be no error, but one is indeed generated because the PATH environment is not properly set for shared libraries that TaubinSmoother needs in order to run. I have tried using:
proc launch {} {
set error_catch [catch {exec $cwd/TaubinSmoother &} error_out detail]
return $detail
}
set cwd [file dirname [info script]]
set error_out launch
puts "$error_out"
This too did not work as I only received a "launch" printed to the stdout. I read TCL, get full error message in catch command and more about catch and return, but the answered question did not work in my case and the examples on the man-pages did not help. How do I get the actual error to return to my running script so I can warn future users of the issues encountered?
Upvotes: 2
Views: 987
Reputation: 3434
Your second attempt fails in the sense of "not meeting your expectation" because the line
set error_out launch
should read
set error_out [launch]
Background: in its original form, it is an assignment of a literal string "launch" to a variable error_out
. Hence, this is what you see printed.
Your exec
runs in background mode (&
). Therefore, your Tcl script is not correlated with the backgrounded process any longer. exec
will just return without signalling any (well, background) error. Better use a bullet-proven Tcl idiom for checking on a background process, using open
and fileevent
:
See Detect end of TCL background process in a TCL script
Upvotes: 3