I have a MatLab project on Win-7.
Its version controled with Git-Extension.
I have a matlab function that runs a kind of self-test.
It's named pre_push_test_suit, and it exits with either code 0 (OK) or 1 (there is a problem).
I want to implement the pre-commit git hook, that will prevent pushing to the central repo if the self-test function fails.
my script starts like this:
#!/bin/sh
res_file=pre_push_test_log.txt
resultcode=$(matlab -automation -minimize -r pre_push_test_suit -logfile $res_file)
if [ "$resultcode" -eq "0" ]
...
Expected result: I wanted the script to lunch MatLab and wait for exit value.
Actual result: the script lunches MatLab process, and continues with empty value in $resultcode.
If I got it correctly, the script is run on a bash-like shell that is installed with git on windows, but I'm not sure it is a real bash.
Typing ps did not show the matlab process.
Also tried, but with no change of result:
...I did not try scripts in any other language but bash (I do not know many scripting languages).
I thought about the ugly solution of infinite loop with "wait", waiting for a file to contain some output, but i prefer something more decent.
Any better solution to wait for the result, in any language, is welcome.
It seems the problem occurs because matlab automatically detaches itself from the shell in windows (this behaviour doesn't happen on Linux with the -nodesktop option).
Option 1:
Use the -wait option:
From Docs
Wait for MATLAB to Terminate
By default, when you call the matlab command from a script, the command starts MATLAB and then immediately executes the next statements in the script. The -wait option pauses the script until MATLAB terminates. Option Result
-wait
Use in a startup script to process the results from MATLAB. Calling MATLAB with this option blocks the script from continuing until the results are generated.
#!/bin/sh
res_file=pre_push_test_log.txt
resultcode=$(matlab -wait -nodesktop -minimize -r pre_push_test_suit -logfile $res_file)
if [ "$resultcode" -eq "0" ]
Option 2:
use octave instead of matlab
Option 3:
use wait to wait for the process to be finished: How to wait in bash for several subprocesses to finish and return exit code !=0 when any subprocess ends with code !=0?
the -nodesktop option should keep the matlab session inside terminal's control.
#!/bin/sh
res_file=pre_push_test_log.txt
resultcode=$(matlab -nodesktop -minimize -r pre_push_test_suit -logfile $res_file)
wait $!
if [ "$resultcode" -eq "0" ]
[there are problems with option 3, see comments]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With