gpt4 book ai didi

linux - 从 Matlab 启动应用程序

转载 作者:IT王子 更新时间:2023-10-29 00:07:41 25 4
gpt4 key购买 nike

我正在寻找一种从 Matlab 中启动应用程序的方法。问题是,我的 Matlab 脚本将一些结果保存到一个文件中,然后应该在关联的应用程序(在本例中为 Blender)中打开该文件。

我熟悉像

这样的命令
system('program_name')

!program_name

和其他一些方法,但问题是,应用程序是使用 Matlab PATH 启动的,因此它会在 Matlab 目录中查找它需要的各种库。例如:

>> !blender
blender: /usr/local/MATLAB/R2011a/sys/os/glnx86/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by blender)

有没有什么方法可以启动使用全局(系统)PATH 的应用程序?

刚才我以为我找到了一个调整,即从 Matlab 中启动一个终端,带有一些参数(Blender filename.blend)。

system('terminal -x blender /home/pieter/Red.blend')

这确实奏效了几次,但现在我在执行此命令大约 20 次后出现错误...

>> system('terminal -x blender /home/pieter/Red.blend')
(terminal:10982): GLib-CRITICAL **: PCRE library is compiled without UTF8 support
(terminal:10982): Terminal-CRITICAL **: Failed to parse regular expression pattern 0: PCRE library is compiled without UTF8 support

顺便说一句,我正在使用 Arch Linx。


编辑:

好吧,我只是想到了一个相当肮脏的解决方案。 Matlab使用环境变量

LD_LIBRARY_PATH

对于必要库的路径:

getenv('LD_LIBRARY_PATH')
/usr/local/MATLAB/R2011a/sys/os/glnx86:/usr/local/MATLAB/R2011a/bin/glnx86:/usr/local/MATLAB/R2011a/extern/lib/glnx86:/usr/local/MATLAB/R2011a/runtime/glnx86:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386/native_threads:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386/client:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386

所以我可以将这些信息保存到一个变量中(例如 MatlabPath):

MatlabPath = getenv('LD_LIBRARY_PATH')

然后在调用 blender 之前执行此操作:

setenv('LD_LIBRARY_PATH',getenv('PATH'))

这使得 Matlab 使用我的系统库。然后在程序启动后,将旧值重新分配给 LD_LIBRARY_PATH:

setenv('LD_LIBRARY_PATH',MatlabPath)

所以...这是一个解决方案,但如果有人知道解决问题的更简洁方法,请告诉我。

最佳答案

正如我在上面的编辑中指出的,这可能是一个解决方案:

% Save library paths
MatlabPath = getenv('LD_LIBRARY_PATH');
% Make Matlab use system libraries
setenv('LD_LIBRARY_PATH',getenv('PATH'))
disp('Starting Blender...')
system( ['blender ', Directory, FileName, '.blend'] )
% Reassign old library paths
setenv('LD_LIBRARY_PATH',MatlabPath)

但是,使用另一种启动应用程序的方法,您可以在启动后立即返回到 Matlab:

% Start Blender and immediately return to Matlab
!blender Geometry.blend &

& 符号 (&) 是启动应用程序后立即返回 Matlab 的关键,但以这种方式启动 Blender 我无法像使用 system(. ..).

所以,任何人都知道如何做

  • 使用 !program_name 和可变文件名

  • 使用 system(program_name) 和一个选项,这样 Matlab 就可以启动应用程序(并且不会等到应用程序关闭才返回)

关于linux - 从 Matlab 启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8340818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com