Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Tcl to get program exit code?

Status
Not open for further replies.

MTsoul

Technical User
Jul 23, 2007
2
CA
Hello,

Simple C program, compiled:

int main(int argc, char** argv) { return atoi(argv[1]); }

The program returns the first parameter as its exit code. How can I launch this program in Tcl and retrieve that exit code?

I tried:

puts [catch {exec program 0}]

but that always shows 0. Any ideas?

Thanks.
 
Hi

For me works better :
Code:
[blue]%[/blue] puts [catch {exec program 0}]
0
[blue]%[/blue] puts [catch {exec program 1}]
1
[blue]%[/blue] puts [catch {exec program 2}]
1
[blue]%[/blue] puts [catch {exec program 100}]
1
[blue]%[/blue] puts $tcl_version
8.4
I have the exactly same results with both the CygWin's and ActiveState's Tcl.

Or what exactly would you like to do ?

Feherke.
 
Thank you for the help. I simply did "puts [catch {exec test #}]", which always gave 0. Unfortunately for me, Cygwin has a binary in /usr/bin/ called test. Even local directory "./test" didn't work, but absolute paths worked just fine.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top