LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-28-2008, 03:02 PM   #1
williamhomanchun
LQ Newbie
 
Registered: Apr 2008
Posts: 17

Rep: Reputation: 0
Just wonder how to get exit status of pragram in tcl code


HI all,

I am trying to find out the exit status from other program in tcl program.
For example, in csh shell, the exit status is in the variable $status

#!/bin/csh -f

echo "Start "
<program>
echo "Status : $status"
exit

But for tcl program, I don't know how to find the exit status of the program, normally we use catch to find if the program is fail or not, but we don't know the exit status of the program. DO you know how to find it ?

if { [catch {exec <program>} message } {
puts "Error : <program> fail with message $message"
}
exit
 
Old 05-30-2008, 07:34 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
quote from activetcl 8.5.2.0 help pages

Code:
To execute a program that can return a non-zero result, you should wrap the call to exec in catch and check the contents of the -errorcode return option if you have an error:

set status 0
if {[catch {exec grep foo bar.txt} results options]} {
   set details [dict get $options -errorcode]
   if {[lindex $details 0] eq "CHILDSTATUS"} {
      set status [lindex $details 2]
   } else {
      # Some kind of unexpected failure
   }
}
quote from man n exec
Code:
       To  execute  a  program  that can return a non-zero result, you should wrap the call to exec in catch and check |
       what the contents of the global errorCode variable is if you have an error:                                     
              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                                                                  
                 }                                                                                                     
              }
note:
never used it, so don't know if it will work
 
Old 06-02-2008, 01:04 PM   #3
williamhomanchun
LQ Newbie
 
Registered: Apr 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks a lot, I will try it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Exit status vedanu Programming 4 06-23-2007 05:13 PM
exit status 127 ashlesha Linux - General 1 07-10-2006 11:33 PM
> Ftp With Exit Status, Ftp with exit status vwvr9 Linux - General 4 02-23-2005 02:53 AM
exit status naflan Programming 2 10-22-2004 12:22 PM
error exit status 30 debian_dummy Debian 2 09-21-2004 10:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration