I have a C program I called hello. All it does is: return 42;
I have the following Tcl code:
catch {exec ./tcl/hello.exe} result
I really thought result would have a 42. Instead, I get the error message: "child process exited abnormally". Any ideas on what to add to the tcl code to execute a C program?
You're doing everything right. exec captures stdout, and since you're program doesn't generate stdout, you get no output. Because you get a non-zero exit code, catch returns the error that it does.
As for where the 42 went to... read more deeply into the exec man page and you'll see the exit code will appear in the global variable errorCode.
Here's an example straight from the exec man page:
set status 0 if {[catch {exec grep foo bar.txt} results]} { if {[lindex $::errorCode 0] eq "CHILDSTATUS"} { set status [lindex $::errorCode 2] } else { # Some kind of unexpected failure } }
Also, I tried bgexec, but my ActiveTcl 8.4.9.1 doesn't recognize it. Where
can I get bgexec?
It's part of the blt package. You don't need it for something as simple as what you're doing.
嘿!什麼尋找一個很好的資源,你有!與我們自己的幫助你組織本博客?
回覆刪除