1

I have a a problem with running a program in matlab by either the use of a batch file or just the dos() function. I can now open a program en run it with the input by using:

start program.exe input.mdu

But when the computation is finished is does not close on its own. I tried taskkill, taskkill in combination with /wait, close, quit, end, done etc. I have no experience with this at all and can't find any information on this problem. When I tried different commands I either could not get it to close at all or it closed before the computation was finished.

I can get it to work in cmd by the use of taskkill. It then waits until the program is finished, but when I put it in a batch file or in the dos function in Matlab problems start occuring.

1
  • 1
    Which version of Windows you have? Notice that last Widows with DOS was 98 (or Millenium?). In later Windows versions there is command line which replaces DOS and uses DOS syntax, but thats not DOS operating system.
    – Kamil
    Commented Sep 11, 2014 at 11:01

4 Answers 4

1

Have you tried using !program.exe input.mdu ? This should return control to Matlab after program.exe is run. See the section on exclamation point in help punct

EDIT: This will not help if the program does not quit though.

1
  • Oh I didn't you could do that. Very nice. But you are right, it still does not work because the control is not returning to matlab. Commented Sep 11, 2014 at 12:51
0

If you start program without start command (which creates new window), like this:

program.exe input.mdu

you may be able terminate it by pressing CTRL+BREAK.

If you have to use start to run program - you should press that key combination when your program window has focus.

From MSDN (link):

The CTRL+C and CTRL+BREAK key combinations receive special handling by console processes. By default, when a console window has the keyboard focus, CTRL+C or CTRL+BREAK is treated as a signal (SIGINT or SIGBREAK) and not as keyboard input. By default, these signals are passed to all console processes that are attached to the console. (...) CTRL+BREAK is always treated as a signal, but an application can change the default CTRL+C behavior (...)

1
  • I do not want to put in anything manually, because otherwise I could just press the cross en close the program and there would be no problem. The matlab script continues normally when I close it by hand. Commented Sep 11, 2014 at 12:14
0

Killing a process is fairly easy with a batch file, but how can DOS (or more probably, Windows command session, which is not DOS) know when MATLAB has finished its computation? You could have MATLAB write a file when it is done and use that as a signal. But I think you are going about this all wrong.

MATLAB knows when it has finished, yes? And you must have some type of MATLAB script that runs your computation. And MATLAB has an EXIT command.

So simply incorporate the EXIT command into your MATLAB script.

3
  • I think I was not clear before. I have a matlab script that keeps running on a remote desktop for as long as want. In that script I want to start a program which I did not write myself and needs to be visible. That program (with input file) calculates something predictive for the next day. Than this does is again the next day. But the loop gets stuck in matlab, because the program does not close after it is finished. And I think I mean the windows command line, but the commands looked the same as dos, so I thought it was the same. So matlab does not no when it is finished no. Commented Sep 11, 2014 at 12:11
  • @Problem1000 So how does anyone know when it's finished?
    – Peter
    Commented Sep 11, 2014 at 12:22
  • I don't know. I know that it is finished. The program knows that it is finished. Can't I say to the program: close when you're finished calculating ? Commented Sep 11, 2014 at 12:33
0

Ok thanks for taking the time for my problem, but I now think there is not really a solution. I mailed the progam makers to include something that would make it close autmatically after the simulatioin. And they are doing that for me now. So thanks anyway!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .