How do I force a compiled function to exit with a non-zero status yet allow the overall application to continue to run.
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an application that executes several compiled functions using the 'system' command...
e.g.
status1 = system('mycompiledfnc1.exe');
if status1==0 then
status2 = system('mycompiledfnc.exe');
end
I want to force 'status1' to a nonzero value under certain conditions (e.g. nonexistent file) but I am not able to do that. I have tried throwing an error using:
error('my error message')
... but that just seems to throw the error and then freeze execution of the overall application. If I trap the error and exit more gracefully it just returns status=0 (normal execution). Is there a way to force the return 'status' to a nonzero value while allowing the overall application to continue to execute? (fyi... I am using version 2014b).
1 commentaire
Adam
le 27 Oct 2014
Can't you trap your error and in the catch of the error set status to a nonzero value yourself?
Réponses (2)
Robert Cumming
le 27 Oct 2014
You want to in effect transfer information from one exe to another. Is that correct?
Since you are using the system command there is not much you can do, you could parse the message returned (this is stuff written to terminal window)
A better way would be to save information from exe1 and then load it in exe2. Assuming you have access to the source code of both....
Geoff Hayes
le 27 Oct 2014
You haven't mentioned how you build/compile your compiled function executable, but if it is written in C/C++, then you may be able to do something like the following which makes use of its return value. If I write a very simple program like
#include <stdio.h>
int main(int argc, char *argv[])
{
return argc;
}
it just returns the number of input arguments. Saving the above to a file called main.c and compiling (outside of MATLAB) as
gcc main.c -o main.exe
then I can run this function using MATLAB's system as
>> system('./main.exe')
ans =
1
>> system('./main.exe 1')
ans =
2
>> system('./main.exe 1 ''string''')
ans =
3
So as the number of inputs increase, the return value of the function increases as well. So in this instance, we are able to programmatically manipulate the status returned by system. (If your code generates an error, then just return one or some other non-zero value.)
1 commentaire
Voir également
Catégories
En savoir plus sur MATLAB Compiler dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!