Run MATLAB executable from Python

12 ビュー (過去 30 日間)
Deepa Maheshvare M.
Deepa Maheshvare M. 2022 年 12 月 21 日
コメント済み: Al Danial 2022 年 12 月 29 日
Hi All,
I have an executable file (main.exe) which reads user-input from input.ini and also uses the other files below.
In MATLAB's command prompt, I run the executable like this
!main
I am not sure how to run this file from Python.
Suggestions will be of great help.
  3 件のコメント
Deepa Maheshvare M.
Deepa Maheshvare M. 2022 年 12 月 21 日
編集済み: Deepa Maheshvare M. 2022 年 12 月 21 日
I tried,
exe_str = r"C:/Windows/System32/cmd I:/sim/main/main.exe"
process = subprocess.Popen(exe_str, stderr=subprocess.PIPE, creationflags=0x08000000)
process.wait()
but the output file has not been saved to the output folder. There is no issue while running the !main i.e output file is created.
Al Danial
Al Danial 2022 年 12 月 29 日
Try it like this:
import subprocess
exe_str = "I:/sim/main/main.exe"
result = subprocess.run(exe_str, capture_output=True, text=True)
print("STDOUT=", result.stdout) # optional
print("STDERR=", result.stderr) # optional

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by