Last active
June 30, 2017 04:15
-
-
Save vadimkantorov/56f6eb35fab2135c04706a0a67aa2fe6 to your computer and use it in GitHub Desktop.
A Bash script that runs a MATLAB script and closes it immediately after. Assumes matlab executable is discoverable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Installation: add the following alias to your ~/.bashrc | |
# alias matlabr='bash <(curl -sS https://gist.githubusercontent.com/vadimkantorov/56f6eb35fab2135c04706a0a67aa2fe6/raw)' | |
# Usage: | |
# matlabr /path/to/script.m | |
# matlabr --fixlibstdc++ /path/to/script.m # to preload system's libstdc++ before running MATLAB. This will help for erors like: | |
# Invalid MEX-file '/PATH/TO/MYMEX.mexa64': /PATH/TO/MATLAB/ROOT/linux64/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: | |
# version `GLIBCXX_3.4.20' not found (required by /PATH/TO/SOME/LIBRARY/LINKED/TO/MYMEX.mexa64/MYLIBRARY.so). | |
SCRIPTDIR=$(cd "$(dirname "${@: -1}")" && pwd) | |
SCRIPTBASENAME=$(basename "${@: -1}" .m) | |
if [ "$1" == --fixlibstdc++ ]; | |
then | |
PRELOADFIX=$(/sbin/ldconfig -p | grep stdc++ | sed 's/.*=> //' | head -n 1) | |
fi | |
LD_PRELOAD=$PRELOADFIX matlab -nodesktop -nosplash -r "addpath('$SCRIPTDIR'); try, $SCRIPTBASENAME; catch exception, disp(exception); disp(exception.message); disp(exception.cause); for i=1:length(exception.stack); disp(exception.stack(i)); end; exit(1); end; exit(0)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment