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:
- to replace the $(...) with
...
- to add "wait" after the third line
- google it.
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.
matlab
is probably forcibly disassociating itself from the controlling terminal (to run as a windowed/etc. application. You need to see if it has a no-daemon, no-background or foreground command line argument you can give it to make it not do that. Many programs that do this sort of thing have such an option.