필터 지우기
필터 지우기

Run MATLAB executable from Python

조회 수: 38 (최근 30일)
Deepa Maheshvare M.
Deepa Maheshvare M. 2022년 12월 23일
편집: Roshan Swain 2022년 12월 26일
Hi All,
I am trying to run a MATLAB executable (main.exe) from Python. main.exe file was generated using the .m files in my project, using the application compiler.
To run the executable from Python, I tried
import subprocess
cmd = r"C:/Windows/System32/cmd I:/sim/main/main.exe"
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, creationflags=0x08000000)
process.wait()
But this doesn't generate the output file.
In MATLAB's command prompt, when I run the executable (!main) output is saved in the results folder in 50 secs.
But the output file isn't generated while running from Python.
Suggestions on how to run the executable in Python will be really helpful.
  댓글 수: 3
Roshan Swain
Roshan Swain 2022년 12월 26일
편집: Roshan Swain 2022년 12월 26일
Hi,
Try using the communicate() method instead of wait(), like this:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, creationflags=0x08000000).communicate()
Also much better if you place the executable file in the same location as python file for testing( can avoid any path issues for now),
Let me know if this resolves the issue, then I will create an answer for this one.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Python Package Integration에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by