Error preventing me from calling bash script from Matlab

Hi,
I'm having a problem calling a bash script from within Matlab. I have a bash script that basically calls this line of code.
java -d64 -Xmx3G -jar GeneMANIA-v3.3.4.jar QueryRunner --data gmdata-2014-08-12-core --in flat --results result_dir --verbose InputFile.txt
I want to run this iteratively many many times, but with a different InputFile.txt each time, hence why I want to call it within a loop in Matlab (in Matlab, I'm doing various other things before and after that which are essential for my purposes, so I'd prefer to be able to call this one line as well directly from within Matlab).
However, I have tried several things for calling the script from within Matlab, and everytime I get this message:
Error: A JNI error has occurred, please check your installation and try again
Error: A JNI error has occurred, please check your installation and try again
bash runGeneManiaAnalysis.sh: Signal 127
I have tried calling it using:
fname = 'runGeneManiaAnalysis.sh';
unix(sprintf('bash %s',fname));
system(sprintf('bash %s',fname));
!bash runGeneManiaAnalysis.sh
This is a problem that I get only when I try to run it from within Matlab. If I go directly to the Terminal and run it from there, it runs fine without a problem. I'm using Matlab R2014b (8.4.0 150421) 64 bit (maci64).
So can anyone please help me ascertain what's going wrong and how I can fix this issue?
Thanks,
Mike

 採用された回答

Walter Roberson
Walter Roberson 2015 年 5 月 14 日

1 投票

You could be having a PATH or java classpath difficulty. At the terminal prompt, give the command
printenv | egrep -i '(path|java)'
and then at the MATLAB prompt try
!printenv | egrep -i '(path|java)'
and compare the two.

4 件のコメント

Michael
Michael 2015 年 5 月 14 日
Hi Walter,
Yes these do differ completely in what they return.
In the terminal, this:
printenv | egrep -i '(path|java)'
returns
DYLD_FALLBACK_LIBRARY_PATH=/Users/michael/abin
PATH=/Applications/fsl/bin:/Users/michael/Library/Enthought/Canopy_64bit/User/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/michael/abin
In Matlab, this:
!printenv | egrep -i '(path|java)'
returns
OSG_LD_LIBRARY_PATH=/Applications/MATLAB_R2014b.app/sys/openscenegraph/lib/maci64
PATH=/usr/bin:/bin:/usr/sbin:/sbin
XFILESEARCHPATH=/Applications/MATLAB_R2014b.app/sys/java/jre/maci64/jre/lib/locale/%L/%T/%N%S:
BASEMATLABPATH=
DYLD_FRAMEWORK_PATH=/Applications/MATLAB_R2014b.app/sys/os/maci64:/Applications/MATLAB_R2014b.app/bin/maci64/../../Contents/MacOS:/Applications/MATLAB_R2014b.app/bin/maci64:/Applications/MATLAB_R2014b.app/extern/lib/maci64:/Applications/MATLAB_R2014b.app/sys/java/jre/maci64/jre/lib/./native_threads:/Applications/MATLAB_R2014b.app/sys/java/jre/maci64/jre/lib/./server:/Applications/MATLAB_R2014b.app/sys/java/jre/maci64/jre/lib/./lib/jli
DYLD_LIBRARY_PATH=/Applications/MATLAB_R2014b.app/sys/os/maci64:/Applications/MATLAB_R2014b.app/bin/maci64/../../Contents/MacOS:/Applications/MATLAB_R2014b.app/bin/maci64:/Applications/MATLAB_R2014b.app/extern/lib/maci64:/Applications/MATLAB_R2014b.app/sys/java/jre/maci64/jre/lib/./native_threads:/Applications/MATLAB_R2014b.app/sys/java/jre/maci64/jre/lib/./server:/Applications/MATLAB_R2014b.app/sys/java/jre/maci64/jre/lib/./lib/jli
What should I do to fix this?
Mike
Walter Roberson
Walter Roberson 2015 年 5 月 14 日
As an experiment, try adding these before your java invocation in your .sh file:
unset DYLD_FRAMEWORK_PATH DYLD_LIBRARY_PATH
I suspect that possibly the jre that are on the DYLD_LIBRARY_PATH are interfering with the functioning of java that expects a different jre.
Michael
Michael 2015 年 5 月 14 日
Hi Walter,
This did the trick. Thanks so much for the help!
Mike
Arturo Magana
Arturo Magana 2016 年 10 月 24 日
Walter, thank you so much for this answer. I was having the same issue as Michael, this solved everything!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by