How can I send output from MATLAB to the 'stdin' of another program?
11 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2017 年 8 月 10 日
編集済み: MathWorks Support Team
2021 年 5 月 19 日
How can I send output from MATLAB to the 'stdin' of another program?
採用された回答
MathWorks Support Team
2017 年 8 月 10 日
There are two options for sending output from MATLAB to the stdin of another program:
File-based Input/Output
Use a combination of MATLAB and your system's command line to accomplish your desired workflow.
1. Generate the input for the external program in MATLAB and write it to a file:
>> f = fopen('programInput.txt');
>> fwrite(f, '...');
>> fclose(f);
2. Use the '!' operator (or the 'system' command) to run a shell command to read the file, pipe the file contents to the programs stdin, and write the program stdout to a file.
Windows:
>> !type programInput.txt | myprogram > output.txt
Linux/Mac:
>> !cat programInput.txt | myprogram > output.txt
If you need to process the output of the program in MATLAB you can read the 'output.txt' file into MATLAB.
Use MATLAB support for Python or Java
MATLAB provides support for calling Python and Java libraries from within MATLAB. It is possible to start a process using Python or Java and manipulate the stdin / stdout of the process within MATLAB. Refer to the documentation for Java's ProcessBuilder or Python's subprocess.Popen.
For more information about MATLAB support for Python, refer to the following links:
For more information about MATLAB support for Java, refer to the following links:
1 件のコメント
Frank Wiedmann
2017 年 8 月 23 日
編集済み: MathWorks Support Team
2021 年 5 月 19 日
We have implemented a solution for this by using Java, see https://community.cadence.com/cadence_technology_forums/f/mixed-signal-design/37406/communicating-with-the-ncsim-shell-interface-from-matlab-or-octave. I have attached the presentation slides, so that you don't need to register with Cadence. Most interesting for general use are slides 5, 6 and 9 (and the last item of slide 10 if you want to use this solution).
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!