! or system() or unix() - input redirection
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ben Ward
am 24 Jul. 2012
Bearbeitet: Walter Roberson
am 29 Nov. 2015
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 Kommentare
Akzeptierte Antwort
Ben Ward
am 14 Aug. 2012
3 Kommentare
Sönke
am 18 Sep. 2012
Bearbeitet: Sönke
am 18 Sep. 2012
There is yet another way to get fortran programs to work use the env command and undefine the variables this will kill your standard input and output but matlab restores them anyway, somehow.
env -u GFORTRAN_STDIN_UNIT -u GFORTRAN_STDOUT_UNIT -u GFORTRAN_STDERR_UNIT "command including pipes"
from a script
could work
but putting them into a shell file separately from "command including pipes" will somehow still restore the GFORTRAN_XXX_UNIT environment variables even from within the script ??
Weitere Antworten (1)
Walter Roberson
am 24 Jul. 2012
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 Kommentare
Siehe auch
Kategorien
Mehr zu Fortran with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!