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

24 次查看(过去 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
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 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by