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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

errorInfo?

Status
Not open for further replies.

sergelaurent

Technical User
May 30, 2005
52
FR
I want to catch the error code returned by a command whenever it fails without using the catch command!!!!!!

My code is as follows:
set resp [open .....]

When the open command fails, I cannot read the error information returned by this command.

I don't want to use the catch command!!! I found that in tcl, there was a global variable named errorInfo which stores the last error information that occured!!!!

However I don't know how to use it!!! Can someone help me for this command or is there another solution?
 
The obvious question is: why don't you want to use catch?

That may be a psychological question rather than technical. So be it. You're right that errorInfo contains the information from returned errors. In a Tcl shell, I type set a. Since I haven't defined a, Tcl returns: can't read "a": no such variable.

Now since the error has been set, I type set errorInfo. Tcl returns: can't read "a": no such variable
while executing
"set a"


The problem is, without catch the error is real. That is, the script aborts. It is only then that the value of errorInfo is set. This is precisely what catch is for.

_________________
Bob Rashkin
 
You are right Bob!!!

However, I am using an interpreter where the catch command doesn't works!!!!

So I am trying to find another command which would allow me to do the same thing as the catch command!!!!

I want to catch the information from returned errors whithout aborting my script!!! Is this possible?
 
I don't know of any way to catch without catch. That is, other than the old fashioned way: you need to iterrogate the condition that might cause an error. So, in the case of the open, why might you get an error? You can use the various file... statements to determine if the open will be successful before exectution. Something like that?

Why doesn't catch work on your interpreter?

_________________
Bob Rashkin
 
In fact, I am using a modified interpreter where we have added some special commands which would help us to pilote our apparatus!!!!

In fact I am trying to catch information from returned errors of one of our own command!!! While incorporating these commands, we have brought changes to the original interpreter and the catch command causes conflicts!!!!

This is a piece of my script:
set resp [DynOpenLink]
puts $resp

So when the command "DynOpenLink" returns an error, the script is aborted!!!! and i can't catch the information returned!!!

Since the catch command doesn't work, i am trying to find another way round to do the same job!!!
 
Is there some way to explore the conditions pertaining to DynOpenLink? What does that command do? You should be able to anticipate when it will work and when it will fail, no?

_________________
Bob Rashkin
 
This command is used to open a communication channel with our apparatus!!

My goal is to determine if this command works every time!!!
The latter may fails if the connections are not done properly, the link cable used is not appropriate or the cable is not connected!!!

So when I'm using this command, I don't know why it may fail!!!! That is the reason why i'm trying to catch the returned information as each error returns a different code error.
 
The only thing I can think of is to use exec and interrogate the device from the OS. That way, exec won't fail even if the shell command does. You'll only get a shell return code but that might be enough.

_________________
Bob Rashkin
 
It may seem a silly question but how do you use exec with a command? And how do you do to redirect the output to set a variable?
 
In answer to your 2nd question: you can't. At least as far as I know. The exec command will return a 0 or a 1 depending on how the shell command executes.

On the other hand, there is an option for exec that is supposed to direct the output of the shell command and/or standard error to a file, then you could read the file, maybe. I've never used this, myself, so I don't know.

From the help file:
If an arg (or pair of arg's) has one of the forms described below then it is used by exec to control the flow of input and output among the subprocess(es). Such arguments will not be passed to the subprocess(es). In forms such as ``< fileName'' fileName may either be in a separate argument from ``<'' or in the same argument with no intervening space (i.e. ``<fileName'').
...
> fileName
Standard output from the last command is redirected to the file named fileName, overwriting its previous contents.
2> fileName
Standard error from all commands in the pipeline is redirected to the file named fileName, overwriting its previous contents.
>& fileName
Both standard output from the last command and standard error from all commands are redirected to the file named fileName, overwriting its previous contents.

As to your 1st question, the syntax is:
exec <shell command> or set rtnCode [exec <shell command>]

so you might try something like set rtnCode [exec <shell command> 2>filename]

_________________
Bob Rashkin
 
Thanks a lot bong for your help!!! I have changed pieces of the interpreter to return TCL_OK and I can read the error message from errorcode!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top