How can I invoke C++ executable file (.exe) from Matlab code or Simulink?

조회 수: 5 (최근 30일)
I am trying to run a C++ executable file (.exe) from matlab or Simulink. Currently I have to run the ++ executable file (.exe) manually and start the simulation in matlab environment to start the data exchange between matlab and C++ code. Is there any easier way to automate the process? Eg- I can just run matlab/Simulink and the C++ executable file (.exe) is invoked.
Operating system - Windows10
Matlab - 2017a/b
User Datagram Protocol (UDP) is used between matlab and C++
  댓글 수: 5
Honghao Tan
Honghao Tan 2020년 8월 20일
@Walter, thx for your comment on .exe
Rutwesh Shirbhate
Rutwesh Shirbhate 2020년 8월 21일
@walter, Thank you for suggestion

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

채택된 답변

Mohammad Sami
Mohammad Sami 2020년 8월 20일
As Walter suggested you can use .Net System.Diagnostic.Process to run it.
This way you will also be able to terminate the program.
process = System.Diagnostics.Process();
process.StartInfo.FileName = 'java.exe';
process.StartInfo.Arguments = 'some args';
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.CreateNoWindow = false;
process.Start();
processisrunning = ~process.HasExited;
You can then close it as follows
process.Close();
% or
process.CloseMainWindow();
% or terminate immediately
process.Kill();
  댓글 수: 4
Mohammad Sami
Mohammad Sami 2020년 8월 22일
If your exe takes arguments you can specify them with Arguments. If you wish to hide the window of your exe you can see create no window to true. You can find more information in documentation on Microsoft website.
Rutwesh Shirbhate
Rutwesh Shirbhate 2020년 8월 26일
편집: Rutwesh Shirbhate 2020년 8월 27일
Thank you Mohammad for the detailed explaination. The problem for was with the script I created which stopped in between due to a error and the kill statement was not execuated.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 External Language Interfaces에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by