External program is not creating output
古いコメントを表示
Hello,
I am using Matlab R2013a and I want to run an external interactive program as non-interactive from within a matlab-script by piping the Input either through echoing a string or through a text-file. The Input consists of a string and 2 numbers. If I call
echo -e " 'String' \n 1 \n 2.2" | myFotran
in the unix shell, it creates an Output file as expected. Doing the same in matlab with
unix('echo -e " ''String'' \n 1 \n 2.2" | myFotran')
is not generating the Output-file. Why? Can someone help me? I can't change the external program, since it is not mine.
29 件のコメント
Rik
2017 年 5 月 23 日
I have next to no experience with running commandline programs from Matlab, but I generally use system to do that. Confusingly enough, there seems to be no difference between system, dos and unix.
I see no reason why your code shouldn't work, so I'd be interested in the solution as well.
Jan
2017 年 5 月 23 日
Are you sure that it is not generating an output file? Perhaps it is created in an unexpected location? Then providing an absolute path might help.
Matthias Otten
2017 年 5 月 23 日
編集済み: Matthias Otten
2017 年 5 月 23 日
Jan
2017 年 5 月 23 日
@Matthias: I'm not sure, what the current folder is, when you run the unix command. So please try to provide an absolute path instead of searching in the paths you are expecting.
Walter Roberson
2017 年 5 月 23 日
Please cross-check that you are getting the same shell at the command line as you are getting through unix():
echo "$SHELL"
I am wondering whether perhaps you are hitting a situation where the echo you are reaching through unix() is a version that does not support the -e option.
Matthias Otten
2017 年 5 月 24 日
編集済み: Matthias Otten
2017 年 5 月 24 日
Matthias Otten
2017 年 5 月 24 日
Jan
2017 年 5 月 24 日
@Matthias: Did you try to provide an absolut path name for the file?
I do not understand:
I tried it with an input-file that works in the Linux Shell,
but it also does not create an Output-file when started from
within Matlab, although Matlab testifies it worked ( 0 Output).
As far as I understand the shown command pipes the 'String' and the 2 numbers to the command myFotran. But where do you expect the output file to be created?
Matthias Otten
2017 年 5 月 31 日
Matthias Otten
2017 年 5 月 31 日
Jan
2017 年 5 月 31 日
Are you aware that the original question contains "myFotran" repeatedly instead of "myFortran"? Note that Matlab is case-sensitive, such that "System(..." must fail. This is not nitpicking, but such typos in the code could let you think, that the code fails. Unix is case sensitive also, and the "myFotran", "myfortran" and "myFortran" are different things.
If an error occurres, please post a copy of the message. Do not let us guess, what happens.
You still do not get the point I meant:
system('/path/.../myFortran < /path/to/your/folder/Input.txt')
"Input.txt" is searched in the current folder and I'm not sure if the current folder is the same what you run system() or when you open a command shell and run the code there.
Matthias Otten
2017 年 6 月 1 日
編集済み: Matthias Otten
2017 年 6 月 1 日
Walter Roberson
2017 年 6 月 1 日
Does the line
path1/XYZ$ /path2/XYZ/myfortran < /path1/XYZ/Input.txt
indicate that you invoked an interactive shell from MATLAB, and in that shell, your prompt was path1/XYZ$ and you typed in the command
/path2/XYZ/myfortran < /path1/XYZ/Input.txt
?
Matthias Otten
2017 年 6 月 1 日
Walter Roberson
2017 年 6 月 1 日
And is it correct that if you do that
/path2/XYZ/myfortran < /path1/XYZ/Input.txt
in a shell outside MATLAB, that the command works?
I am confused as to whether the problem is occurring on MS Windows or on Linux ?
Matthias Otten
2017 年 6 月 1 日
Jan
2017 年 6 月 1 日
What happens in "line 123 of file myfortran.f"?
Matthias Otten
2017 年 6 月 1 日
Jan
2017 年 6 月 1 日
You do not know the code, but you know, what happens some lines later. "It expects a string there", but the message is "End of file".
Do I understand correctly that the currently discussed problem does not concern the original question "program is not creating output" anymore, but meanwhile the input is not working?
Matthias Otten
2017 年 6 月 1 日
Walter Roberson
2017 年 6 月 1 日
I still think it might be to do with the units. See https://www.mathworks.com/matlabcentral/answers/44388-or-system-or-unix-input-redirection
Matthias Otten
2017 年 6 月 6 日
Walter Roberson
2017 年 6 月 6 日
Did you find a way to get it to work from inside MATLAB? If so please post what you found.
Matthias Otten
2017 年 6 月 6 日
Jan
2017 年 6 月 6 日
Walter has suggested this on 24.05.2017 already, 16 comments before.
Matthias Otten
2017 年 6 月 7 日
Jan
2017 年 6 月 7 日
If you found a solution finally, the discussion was necessary and successful. It is the nature of questions, that a solution is sometimes not efficient.
Please post your solution as an answer and accept it. Thanks.
Walter Roberson
2017 年 6 月 8 日
The shell echo does not use the fortran unit numbers, so I would not have expected the behavior to change for an echo test.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!