Keeping command line programs open while inputting and outputting text files

14 ビュー (過去 30 日間)
I am using a scriptable Fortran-based aerodynamic analysis software called AVL (Athena Vortex Lattice) that accepts text file inputs and writes text file outputs. You can run AVL using the system function like so with a text file listing all commands sequentially:
system('avl.exe < input.txt');
When run using the system function, AVL closes once it reaches the end of the input file, whether commanded to or not. To close AVL, you would type "QUIT" from the base menu (for scripting, put QUIT at the end of your input text file). However, when run using the system function, even if "QUIT" is ommitted, AVL will quit anyway once the end of the input file is reached due to the following error (returned by the system function):
At line 145 of file ../src/userio.f (unit = 5, file = 'stdin')
Fortran runtime error: End of file
I would like to keep AVL open and continue to feed it new input files because this is significantly faster for sequential runs. There is some first time set up AVL must do when opening that does not need to be repeated for subsequent runs. This can be done easily if running AVL by hand by simply continuing to type commands into the command line instead of closing and reopening AVL for each case.
Unfortunately, I cannot figure out how to emulate this behavior with the system function. The ideal behavior I'm seeking is to be able send new lists of commands to AVL by keeping it open indefinitely through the system function, instead of each call to the system function being a self-contained, where AVL is opened, run, and closed.
Is there any way to achieve this behavior with external scriptable programs like AVL?
  2 件のコメント
dpb
dpb 2020 年 7 月 5 日
Probably not...unless there's also a way to switch input from reading from the file to wait for user input from console -- and then you've got the problem of trying to stuff the keyboard buffer from MATLAB.
One thing to check that on outside chance might make a difference -- be sure the last record in your input is terminated with \n (newline) as Fortran is record-oriented i/o. The error message is from the Fortran runtime on an EOF in its input--that's suspicious to me.
You can also try the trailing ampersand "&" after the command line to see if makes any difference -- probably not for this symptom, but worth a try.
Obviously (well I say it's obvious but I presume) if you just submit
!avl &
you get a console window with interactive session?
Is there a command to "READ COMMANDS FROM FILE" that will read your prepared input files and then await more?
If that is so, then you're back to whether can solve the issue to stuff the keyboard buffer of the process from MATLAB and I really don't know if there's a hack to do that or not.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 7 月 6 日
You should be using .Net processes
https://blogs.mathworks.com/loren/2010/12/07/using-microsoft-net-to-expand-matlab-capabilities/
If you were using Mac or Linux you would look in the File Exchange for popen(), but unfortunately that is only unidirectional, so it would probably be easier to use Java processes for bidirectional (unidirectional: you could send the process new commands but not see what it replied)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by