! or system() or unix() - input redirection
古いコメントを表示
I am trying to execute a system command from within Matlab (there is no input or output from/to Matlab, I just need it to call the program and wait).
./forward < input
This works fine in a bash terminal (MACI64), but not from Matlab. I have tried,
!./forward < input
system('./forward < input')
and
unix('./forward < input')
Each time, the input file is ignored.
(I also tried making a shell script containing the full command, but the extra input was still ignored. Also, if I change the name of the input file to one that doesn't exist (e.g. input_null, I get the following error: "/bin/bash: input_null: No such file or directory")
Is there any way to make this work?
thanks.
PS, simpler commands like
!grep -i string < input
work fine from Matlab
3 件のコメント
Walter Roberson
2012 年 7 月 24 日
The program you are trying to run -- was it compiled in gfortran ?
Ben Ward
2012 年 7 月 24 日
採用された回答
その他の回答 (1 件)
Walter Roberson
2012 年 7 月 24 日
0 投票
Please have a look at http://www.mathworks.co.uk/matlabcentral/answers/43640-a-peculiar-problem-when-using-system-command-to-run-a-c-shell-script-from-matlab and at http://www.mathworks.co.uk/matlabcentral/answers/38589-system-or-unix-command-run-compiled-fortran-binary-fails-but-it-runs-fine-from-a-terminal
5 件のコメント
Ben Ward
2012 年 7 月 24 日
編集済み: Walter Roberson
2015 年 11 月 29 日
Walter Roberson
2012 年 7 月 24 日
The thread that had the stderr issue happened to be the first and most detailed of a series dealing with I/O problems with executables compiled with gfortran when used under R2012a . The problem likely is not restricted to stderr.
The reports have been against various operating systems; the library problems might only occur on some of them.
I would recommend contacting Mathworks about this issue; perhaps they have a work-around by now. But in the meantime, it appears that using a different compiler such as g77 makes a difference.
Ben Ward
2012 年 7 月 24 日
Walter Roberson
2012 年 7 月 24 日
Interesting work-around.
カテゴリ
ヘルプ センター および File Exchange で Fortran with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!