How to open External Program by MATLAB?

74 ビュー (過去 30 日間)
Rounak Saha Niloy
Rounak Saha Niloy 2022 年 10 月 6 日
コメント済み: Rounak Saha Niloy 2022 年 10 月 10 日
I want to open an external program named Maxsurf Modeler using MATLAB.
Initilially, I was using system command to open the software as follows-
system('"C:\Program Files\Bentley\Offshore\MAXSURF CONNECT Edition V23\MaxsurfModeler64.exe"')
But the problem of this method is, the code executation does not proceed further unless the program is closed.
How can I open this software and continue the execution of susequent codes?

採用された回答

Walter Roberson
Walter Roberson 2022 年 10 月 6 日
system('"C:\Program Files\Bentley\Offshore\MAXSURF CONNECT Edition V23\MaxsurfModeler64.exe" &');
That is, if you put an & at the end of your command, the MATLAB itself will detect that and cause the program to be run in the background.
I emphasized that it is MATLAB itself doing that because system() specifically documents that it will happen. The alternative would potentially be that MATLAB might have relied upon the system command shell's background-job facilities.
As you appear to be using MS Windows, an alternative approach would be to use System.Diagonstics.Process which is a .NET facility. See https://www.mathworks.com/matlabcentral/answers/583955-get-the-status-using-system-command-when-program-has-been-closed#answer_485480
  3 件のコメント
Walter Roberson
Walter Roberson 2022 年 10 月 7 日
If you use the & at the end of the system() command, then to close Maxsurf you will need to system() a taskkill command.
If you use something like
Exe_Process = System.Diagnostics.Process;
Exe_Process.StartInfo.Arguments = '-example arguments';
Exe_Process.StartInfo.FileName = 'C:\program.exe' % full file path
Exe_Process.Start();
then you could use
Exe_Process.Close();
I am not sure if you need to also
Exe_Process.Dispose();
afterwards.
Rounak Saha Niloy
Rounak Saha Niloy 2022 年 10 月 10 日
Can you help me on using taskkill? I am unable to close the software using taskkill.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by