aman_greval
asked on
How to notify occurance of exception in pro*C file to calling shell script file
I have a shell script that calls a Pro*C file.
Let's assume my shell script a.sh calls b.pc file.
the b.pc file inculdes Pl/Sql statements.
Declare
Begin
Exception;
when others then
end;
Now suppose an exception is raised by the PRO*C file which is caught by it's exception handler.
How can i transfer the exception to the shell file a.sh.
I want the occurance of the exception in b.pc to be notified to a.sh shell script
Let's assume my shell script a.sh calls b.pc file.
the b.pc file inculdes Pl/Sql statements.
Declare
Begin
Exception;
when others then
end;
Now suppose an exception is raised by the PRO*C file which is caught by it's exception handler.
How can i transfer the exception to the shell file a.sh.
I want the occurance of the exception in b.pc to be notified to a.sh shell script
ASKER
Suppose the Pro*C file returned an error:
They how will this work. Pro*C is a language not a function that will return a value:
procapplication arg1 arg2
if [ $? -eq 7 ]
then
echo "exception occured
else
echo "all is fine"
fi
status=`procapplication arg1 arg2`
case $status in
...
They how will this work. Pro*C is a language not a function that will return a value:
procapplication arg1 arg2
if [ $? -eq 7 ]
then
echo "exception occured
else
echo "all is fine"
fi
status=`procapplication arg1 arg2`
case $status in
...
$? refers to return status of last executed command. In Pro C you would something like exit or return (from main) which would be capable of exiting the application with a status code.
>status=`procapplication arg1 arg2`
For this to work, application needs to _print_ the status and not return it.
>status=`procapplication arg1 arg2`
For this to work, application needs to _print_ the status and not return it.
ASKER
status=`procapplication arg1 arg2`
This statement assigns value not print any value.
This statement is equivalent to pro*c application assigns the return code (as a function does) to status.
which is not true.
This statement assigns value not print any value.
This statement is equivalent to pro*c application assigns the return code (as a function does) to status.
which is not true.
the backticks around `procapplication arg1 arg2 ` will make the shell execute the procapplication along with the specified arguments and assign the OUTPUT to status. Since you are printing the error code, it gets assigned to status
ASKER
status=`procapplication arg1 arg2`
Sunny, can you tell me how to assign the value to status within the procapplication.
If i can do something like this it will be great. Just what i need.
Sunny, can you tell me how to assign the value to status within the procapplication.
If i can do something like this it will be great. Just what i need.
>can you tell me how to assign the value to status within the procapplication.
status is shell script variable ... invisible inside the ProC unless ... That variable is part of enviroment that is passed to the application and ProC application can get/set environment variables
To pass variable as part of enviorment, all you need in the script is
status=0
export status
status is shell script variable ... invisible inside the ProC unless ... That variable is part of enviroment that is passed to the application and ProC application can get/set environment variables
To pass variable as part of enviorment, all you need in the script is
status=0
export status
ASKER
i know that to pass variables to procapplication i need to pass as part of the environment. such as statis=0 export status
Now status will work as a global variable can be accessed from any program.
So you mean to say assign a value to status in procapplication. As it is a global variable it will be accessible to shell scirpt calling procapplication. Am i right.
Now status will work as a global variable can be accessed from any program.
So you mean to say assign a value to status in procapplication. As it is a global variable it will be accessible to shell scirpt calling procapplication. Am i right.
>such as statis=0 export status
>Now status will work as a global variable can be accessed from any program.
No .. Environment variable is not same as global variable ... e.g. PATH is an environment variable ... When you exec() an application, PATH is searched for its location ... However, it cannot be accessed as a global variable
man getenv
man setenv
>Now status will work as a global variable can be accessed from any program.
No .. Environment variable is not same as global variable ... e.g. PATH is an environment variable ... When you exec() an application, PATH is searched for its location ... However, it cannot be accessed as a global variable
man getenv
man setenv
ASKER
sunny, i just want to know how do i set a variable in procapplication that can be referenced in the calling shell application.
if i say,
a.sh
:
:
:
export result=0
result:=procapplication
:
:
procapplication
begin
:
:
result:=0;in the same
exception
result:=1;
end;
Now, will this solve my purpose. Will the result variable that is being set in the procapplication available in shell script a,sh
If no then tell me by giving me a dummy example that is designed simillar the example i have provided.
And if you can't do that please leave it unsolved.
Thanx
if i say,
a.sh
:
:
:
export result=0
result:=procapplication
:
:
procapplication
begin
:
:
result:=0;in the same
exception
result:=1;
end;
Now, will this solve my purpose. Will the result variable that is being set in the procapplication available in shell script a,sh
If no then tell me by giving me a dummy example that is designed simillar the example i have provided.
And if you can't do that please leave it unsolved.
Thanx
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
sunnycoder, I have to say I think your suggestion re the env is off track. The C program is a process with its own environment. When the C program exits, that environment is lost. The controlling shell has no access to the C program's environment, except possibly a very tenuous one via the proc filesystem. For the C program to communicate with the shell *and* keep running, it has to send a signal as I posted earlier. Also it can communicate with the controlling shell with its exit code, but then it's no longer running.
duncan_roe, You are right ... Env method wont work ...
ASKER
I have seen that if a shell script a.sh calls a procapplication. Then a ProcApplication can exit with an exit code like exit(1) and this can be catched in a shell environment. for example:
a.sh
:
:
procapplication.pc
if $? !=0 then -- this works.
:
:
procapplication
:
:
if ...
exit(1)
end;
a.sh
:
:
procapplication.pc
if $? !=0 then -- this works.
:
:
procapplication
:
:
if ...
exit(1)
end;
Suggest split sunnycoder / duncan_roe
I second that
> How can i transfer the exception to the shell file a.sh.
>
> I want the occurance of the exception in b.pc to be notified to a.sh shell script
There is no concept of catching an exception in a shell script .. However, what you can do is:
a) If a return status alone will suffice, your C application can return an error code which will notify the shell script that an error has occured. Something like
procapplication arg1 arg2
if [ $? -eq 7 ]
then
echo "exception occured
else
echo "all is fine"
fi
b) If you want to commincate different errors, your Pro C application can print the error
status=`procapplication arg1 arg2`
case $status in
...
c) Yet another option is to have a pre-decided file (/tmp/myfile.tmp) in which Pro C will output all the information that it needs to pass back to shell script and shell scrit can read that file later on.
Cheers!
sunnycoder