MATLAB Answers

Can't run external program

124 views (last 30 days)
Paul Tartabini
Paul Tartabini on 9 Dec 2016
Commented: Nicolas Juarez on 1 Sep 2020 at 17:10
I have C program that I compiled and can run in a command window without a problem. I am trying to execute from the matlab command window using the ! operator:
When I do this command, matlab seems to accept the line without an error, but the code is not executed. I have tried the system command (nothing happens but I get a returned results of -1.073741515000000e+09). If I execute system commands like !del junkfile.txt
the file gets deleted. But nothing happens when I run my external program. I have tried calling with the full path, but that does not work and I get the same behavior.
Would appreciate any help you can give,
- Paul


Nick Blackwell
Nick Blackwell on 11 Oct 2017
I have the identical problem. I can run my program from the Windows command line, and I can run other system commands from Matlab no problem, but this one isn't working. It's on the system path and user path, as well as Matlab path, but nothing happens when I send that system command. Gives back the status of -1073741511. I've tried using !, system(), and dos(). I can even use "!where myprogram" and it gives the right location. I have tried running it from within the folder it's in, as well as from another folder, with the same result. Any help?
Josh Philipson
Josh Philipson on 7 Feb 2020
Paul, Nick,
Did you ever figure this out? //josh

Sign in to comment.

Answers (3)

Philipp Krauter
Philipp Krauter on 30 Dec 2018
The problem is that newer versions of Matlab are adding a folder to the Path environmental variable each time, the system() or dos() function are called. For me, removing this new path by calling
system('set path=%path:C:\Program Files\MATLAB\R2018b\bin\win64;=% & myprog.exe');
instead of
solves the problem.
Please note, that the folder to be removed from the environmental variable can differ. It can be read out using


Shilpa Nayak
Shilpa Nayak on 26 Nov 2019
thanks, this solved it!
I had the exact same issue, with any application that used Windows drivers. I use MATLAB 2018a.

Sign in to comment.

Josh Philipson
Josh Philipson on 7 Feb 2020
Edited: Josh Philipson on 8 Feb 2020
Hi, I think I may have found something potentially helpful.
I had a very similar issue, and just resolved it. In case it's relevant, I was using Intel's Fortran compiler in a Visual Studio project to build a fortran file. TLDR; The built EXE was trying to load some dll that it couldn't do from within MATLAB, but within native windows cmd window, or double-click, evidently it could load it.
The relevant bit was from the magician, "Ian H (blackbelt)", over at who posted this bit:
  • You need to change the runtime library setting for your project within Visual Studio - the default within Visual Studio is to produce an executable that requires the Fortran runtime libraries.
  • Change to a Release configuration, then rIght click on your project in the solution explorer, select Properties, then in the Configuration Properties > Fortran > Libraries page change the Runtime Library option to "Multithreaded". Rebuild your project.
  • (If you use OpenMP within your project, then you will still have a dependency on some of the OpenMP DLL's.)
I sort of backed into this when I tried to run my compiled .exe on another PC that didn't have the same build environment setup, and it barfed on me indicating "libmmdd.dll" was not found. Additionally, I tried system('cmd &') to have Matlab open up a command window..and I found that one compiled version (i.e. via G77) worked, and the one I used Visual Studio for, didn't work!
From there I guess that it couldn't load that library in the MATLAB "system" scaffolding. I am not sure.
Regardless, for me the key was changing the "Runtime Library" option to "Multithreaded", from "Multithreaded dll". As soon as I could do it, the exe was runnable. Note: runnable from within Matlab, as well as runnable on the other Windows PC, that did not have the same development-environment. Seems all dependencies was 'packaged' into the fortran .exe.
Hope this helps someone! :)


Sign in to comment.

Image Analyst
Image Analyst on 9 Dec 2016
Try the dos() function instead.
Is the current folder the folder with the executable that you're trying to run?
Can you get a console window in the operating system and run the program from that? What operating system are you using?

  1 Comment

Nicolas Juarez
Nicolas Juarez on 1 Sep 2020 at 17:10
dos() seem to work for me, thanks for the help!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!