1

我有一个我想从 MATLAB 运行的 fortran 代码的可执行文件。

我尝试使用以下两个选项,但出现错误:

!/home/atrac/code case172.jcl
error:- ls: cannot access ./id: No such file or directory
ls: cannot access ./id: No such file or directory

!gnome-terminal --command "./home/myhome/code case12.jcl"
error: There was an error creating child process for this terminal

有没有办法可以编写一个 shell 脚本来执行程序并暂停 Matlab 直到执行外部程序然后将控制权传回给 Matlab?

我正在尝试在 Matlab 中运行一个遗传算法,它调用这个外部软件。非常感谢任何想法或帮助。

谢谢, 亚什

4

3 回答 3

1

Okay, looks like two different things going on here. Both are probably related to Matlab's current directory.

!/home/atrac/code case172.jcl
error:- ls: cannot access ./id: No such file or directory
ls: cannot access ./id: No such file or directory

Here, it looks like you're managing to run your code program, but code or the JCL script is looking for a file named id in the current working directory. When you shell out from Matlab, that's going to be Matlab's current directory. Run pwd from the Matlab command prompt to find out where you are. You can probably fix this by using cd in Matlab to move to the directory where the id file actually exists (I'm guessing it's in /home/atrac), and then running code using the same command line. A better fix would be to rewrite code and/or the JCL script to work when run from any path (maybe by using absolute paths), so your cwd doesn't matter.

!gnome-terminal --command "./home/myhome/code case12.jcl"
error: There was an error creating child process for this terminal

Here, the leading "." is probably messing it up, because it's now looking for home/myhome under the current working directory, instead of under the root directory. Try doing !gnome-terminal --command "/home/myhome/code case12.jcl" (without the ".") instead.

于 2013-08-09T04:28:30.807 回答
1

理想情况下,这应该作为评论,但我没有足够的声誉。

但尽管如此,创建子进程的错误与 MATLAB 无关。外壳出错了。你能从终端运行程序吗?

其次,您正在使用:

!/home/atrac/code case172.jcl 

但你应该使用 !./home/atrac/code case172.jcl

于 2013-08-07T15:24:30.910 回答
0

当包含该文件的文件夹不在 MATLAB 可见的 UNIX 系统路径上时,您可以从 MATLAB 运行 UNIX 程序。要确定对 MATLAB 可见的系统路径,请在命令行窗口中键入以下内容:

getenv('PATH')

您可以修改为当前 MATLAB 会话或后续 MATLAB 会话持续存在的系统路径,如以下部分所述。

修改当前 MATLAB 会话的系统路径。执行以下操作之一:

Change the current folder in MATLAB to the folder that contains the program you want to run.

Issue these commands using the Command Window:

path1 = getenv('PATH')
path1 = [path1 ':/usr/local/bin']
setenv('PATH', path1)
!echo $PATH 

如果您重新启动 MATLAB,该文件夹将不再位于 MATLAB 可见的系统路径上。

http://www.mathworks.com/help/matlab/matlab_env/creating-opening-sharing-and-deleting-files-and-folders.html#f0-38522

于 2013-08-08T13:44:39.470 回答