Terminate an application called by system() after fixed amount of time

조회 수: 17 (최근 30일)
Hello,
I have an application that interfaces with a third party software and receives UDP datagrams in real time. The application, when opened, stays open indefinitely and does not terminate. I want to read the output of the program and save numerical data to the MatLab workspace in real time.
The only way I can think of doing this is to open and close the application iteratively in a loop, saving the output (which prints in the command window) using diary, then reading the output with another script that pulls out the numerical values I want and save them in MatLab.
The issue I'm having is that the application does not terminate on its own. It stays open indefinitely and does not accept and user input. When run in MatLab using system(), it stays open until I break it using Control+C. How do I implement code in MatLab to terminate an application that is currently occupying the command window?
The furthest I got in the past few days of research has been to use the parallel computing toolbox, and use parfeval to asynchronously insert some kind of break after running a separate timer function inside of a loop under parfor.
I'm by no means an expert MatLab user but there has to be a way to make an application time out or stop in MatLab after it begins running, without using control+C.
Here is the application that I am trying to call and close on a time basis in MatLab:

채택된 답변

Nagarjuna Manchineni
Nagarjuna Manchineni 2017년 6월 20일
See the following link that discusses on how to create and kill the process after some time:
In addition to the above implementation, you can use the 'timer' function to create a timer object that executes the desired functionality after a certain time (mentioned while creating the timer object). You can use that to kill the spawned process if it still running after your desired time.
See the following documentation link for more information on timer class:
  댓글 수: 1
Sajid Afaque
Sajid Afaque 2019년 12월 18일
But what if i only have to wait and kill only for some iteration ?
i dont want to wait so long for all the iteration.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by