How to kill an executable ran by system command and close the cmd window

14 ビュー (過去 30 日間)
yael alon
yael alon 2021 年 4 月 25 日
コメント済み: Nukul Shah 2022 年 2 月 2 日
I'm running an executable in the following order, so i could close it after a certain time is passed:
system([exe_name ' &']);% Open executable
if time>time_th
system(['TASKKILL -f -im "' exe_name '"']); % Close executable
When i use the kill command, the executable stops running, but the cmd window stays open for unknowen reason.
I don't want to "kill" cmd windows because we may have another necessery cmd window open in the background.
How can I kill the executable while making sure that I'm closing also the cmd window?

採用された回答

Jan
Jan 2021 年 4 月 25 日
You could try to start the executable through Java instead of opening a CMD window:
runtime = java.lang.Runtime.getRuntime();
process = runtime.exec('exename'); % non-blocking
...
process.destroy();
% Might be useful:
% rc = process.waitFor(); % block Matlab until external program ends
% rc = process.exitValue(); % fetch an ended process' return code
  2 件のコメント
yael alon
yael alon 2021 年 4 月 26 日
Works great! thank you
Nukul Shah
Nukul Shah 2022 年 2 月 2 日
How do we read the STDOUT in this case though?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSchedule Model Components についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by