MATLAB Answers

call and run an external program in matlab under windows

254 views (last 30 days)
Cenk OZAN on 13 Jul 2011
Commented: Ahmed Abed on 15 Jun 2017
Does anybody have any idea about how to call and run an external program in matlab under windows? I want to call an external program in Matlab and this external program should read its input file in Matlab directory and then this external program should create the program's output file in Matlab directory.

Answers (5)

Rick Rosson
Rick Rosson on 13 Jul 2011
You can call an executable program from the command line using the exclamation point or the system command:
>> !hello
will cause Windows to execute the program hello.exe if there is such a file in the current directory or on the system path.
>> system('hello');
will do the same thing.
Ahmed Abed
Ahmed Abed on 15 Jun 2017
I have been in the same situation, you can try the following code: system('C:\folder\programme.exe C:\folder\file same.DAT'); this is just an example, you need to enter the path of your programme then the path of the file to be analised. this way worked fine with me, however, if the external programme needs a human interference after finishing the analysis, then you need to manually close the programme so you can complete your code, and this is exactly where I am stuck currently.

Sign in to comment.

Aleksander on 13 May 2013
Would it be possible to launch an program from matlab code without keeping in the matlab program. my issue is that when i launch it this way matlab will wait for the external program to close before it continues.
  1 Comment
Kaustubha Govind
Kaustubha Govind on 13 May 2013
Aleksander: If you're on Linux, I think adding an ampersand (&) to the end of your command should do what you need.

Sign in to comment.

Cameron on 19 Jun 2013
Can anybody add some go-by code on how I would type commands, send files, etc in the externally opened program? I want to run hyperterminal externally with Matlab and send/receive text automatically on teh opened serial port.

Veronica Escobar Ruiz
Veronica Escobar Ruiz on 9 Sep 2015
Hi Cenk OZAN, did you find a solution for your problem? I have the same issue. I tried, without success, the solutions above and also the solution below.
[status1,cmdout1]=system('explorer /select ,"InputFile.txt"')
Hope someone can help us.

Javier Valdes
Javier Valdes on 9 Aug 2016
Edited: Walter Roberson on 9 Aug 2016
I think that the keyinject function could be useful to control that external application from MATLAB (if the external application has a named window).

Community Treasure Hunt

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

Start Hunting!