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!

reading csh script return codes

Status
Not open for further replies.

BTCMan

Programmer
Jun 17, 2005
21
BR
Hi all,

I have to execute a unix cshell script inside my TCL script and then read its return code. The cshell script return codes can be:
0 - 100 % success
1 - partial success
2 - error

The dummy cshell script named "dummy_script.sh" is below:
-------------------
#!/bin/ksh

echo Cshell SCRIPT FILE Execution!
exit 2
----------------

I tried the following code in my TCL program but it only recognizes return codes 0 or 1 (not 2 per example):

------------------------
if { [catch {exec dummy_script.sh} errorCode] != 0} {
puts "returned non zero value!"
# now I want to print the errorCode (which should be 2)
puts $errorCode
} else {
puts "returned zero value!"
}
-----------------

When the line "puts $erroCode" is reach the output is
"child process exited abnormally". I expected the output as 2.

Can anybody help me to figure out how to retrieve the correct return code?? Thanx!

BTCMan
 
Look here:
I've never done this but this is what it says on the "wiki":
On comp.lang.tcl, Ulrich Schoebel shows this as an example of how to get at the exit code of a command being exec'd in Tcl:

if {[catch {exec grep -q pippo /etc/passwd} result]} {
# non-zero exit status, get it:
set status [lindex $errorCode 2]
} else {
# exit status was 0
# result contains the result of your command
set status 0
}

_________________
Bob Rashkin
rrashkin@csc.com
 
Hi Bong,

the hint worked fine after I defined as "global" the reserved variable "errorCode" inside my procedure.
A workaround to capture the cshell script return code at unxi level is: "echo $?" - this will retrieve the script execution's exit code that can be parsed later.
See ya!


BTCMan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top