Unexpected errors while running external program from Matlab on Linux
4 views (last 30 days)
Show older comments
I am trying to call an external program from Matlab. In this specific case the program is ESA software NEST for the processing of radar images. The NEST program should run from command line and thus needs arguments. I will clarify.
The weird thing is the following. If I run the exact same line of code outside of Matlab (thus on Linux command line) it works without any problem:
$ cd [pathname_nest] && gpt.sh [pathname_graph]/graph.xml
Here the graph is an xml used as an input for the software. So, this works fine.
When I do this through Matlab it never works, whether I use:
system('cd [path_nest] && gpt.sh [path_graph]/graph.xml')
or
!cd [path_nest] && gpt.sh [path_graph]/graph.xml
(of course whereby the text between brackets contains the right paths)
Now, the error is a full list, beginning with:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
and many more, but all related to java.
It is most probable that the java environment Matlab needs (and is able to find when using Linux command directly) cannot be found, executed and/or read when executing the command through Matlab. Obviously, Matlab is able to execute the commands, though it is not processed correctly. This is what I do not understand. If I execute a Linux operating system command through Matlab it should then be independent from the Matlab environments and execute this outside Matlab (and in the Linux environment), or am I mistaking?
I tried several possible workaround, including executing a Unix script (containing the same lines) called by Matlab and adding the paths of the software and the java folders. However, nothing works.
Could someone please help me? Thank you.
ps. the Matlab is run on the same server. Actually it is opened from the same path as where the described Linux command lines can be successfully executed.
0 Comments
Answers (1)
Walter Roberson
on 1 Oct 2015
You probably need to setenv() the Java paths before calling the program, or alternately have the command line set the java variables. Use
!printenv
to see the variables being set. DYLD_LIBRARY_PATH will almost certainly need to be changed. On OS-X DYLD_FRAMEWORK_PATH and possibly XFILESEARCHPATH would also be relevant.
2 Comments
Walter Roberson
on 4 Oct 2015
Inheriting environment variables is the normal Linux environment.
Sometimes you can get around problems like this by explicitly invoking the shell in login mode, something like
system('bash -l -c "cd [path_nest] && gpt.sh [path_graph]/graph.xml"')
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!