How do I force a compiled function to exit with a non-zero status yet allow the overall application to continue to run.
7 views (last 30 days)
I have an application that executes several compiled functions using the 'system' command...
status1 = system('mycompiledfnc1.exe');
if status1==0 then
status2 = system('mycompiledfnc.exe');
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).
Robert Cumming on 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 on 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
int main(int argc, char *argv)
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 1')
>> system('./main.exe 1 ''string''')
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.)