Closing windows CMD window after executing system and run through a certain algorithm

8 ビュー (過去 30 日間)
I want to use 'system' to open another software in cmd as well as forming a java socket between them to allow exchanging datas for calculation, as shown in the code below
% command to execute in cmd to form socket
commandString = strcat('"', this.FreeFlyerPath, 'FreeFlyer.exe"', ...
' -r -mp "', this.MissionPlanPath, '\sample.MissionPlan"', ...
sprintf(' -ui %d -ui %d -ui %s &', portNum(1), portNum(2), this.terminationCode));
system( commandString );
%
%
%
%
% some algorithms
%
%
%
% how to close the cmd?
However, the function has to be looped multiple times, that means the cmd windows keep popping out like a virus without exiting. I tried system('exit') and it does not work. May I know the correct way to close the cmd window after executed the function?
  1 件のコメント
Walter Roberson
Walter Roberson 2025 年 1 月 8 日
Have you considered instead using the .NET interface System.Diagnostics.Process ?

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

採用された回答

Tan
Tan 2025 年 1 月 8 日
Alright it turns out the command
system('taskkill /IM cmd.exe /F')
works, it required /F to force stop the cmd process

その他の回答 (1 件)

Jacob Mathew
Jacob Mathew 2025 年 1 月 3 日
Hey Tan,
You can try passing /c along with your command string. This parameter will terminate the Windows cmd after executing the command. You can refer to it in Microsoft's documentation below:

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by