Can't run external program

52 次查看(过去 30 天)
Paul Tartabini
Paul Tartabini 2016-12-9
评论: Image Analyst 2025-2-13,23:00
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:
>>!myprogram.exe
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
  4 个评论
Ajith Kumar Veeraboina
Hello Paul,
I am looking for solution to the exact same issue. Are you able to resolve it.
Walter Roberson
Walter Roberson 2021-4-3
-1073741511 is hex C0000139 which appears to correspond to the Windows error code for "Entry point not found" . That indicates that you either tried to execute something that was inherently not properly created (such as if you tried to directly execute a DLL that did not have a main program), or else that the program you executed tried to use a DLL that could not be found.

请先登录,再进行评论。

回答(6 个)

Philipp Krauter
Philipp Krauter 2018-12-30
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
system('myprog.exe');
solves the problem.
Please note, that the folder to be removed from the environmental variable can differ. It can be read out using
system('path');
  3 个评论
Dan
Dan 2021-3-17
Hey Philipp, thanks for your post. But I tried your method, there is still the matlab in the Path environmental variable, and the external program still could not run. I use MATLAB r2021a.

请先登录,再进行评论。


Josh Philipson
Josh Philipson 2020-2-7
编辑:Josh Philipson 2020-2-8
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 https://software.intel.com/en-us/forums/intel-fortran-compiler/topic/759093 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! :)
Josh

Image Analyst
Image Analyst 2016-12-9
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?

Avner Atias
Avner Atias 2020-11-1
Hi guys,
I know it's been a while and this issue may be resolved. I solved it in another approach. To bypass the faulty 'system' MATLAB command, the C++ program (or any other for that matter) can be ran via a BATCH file. Wrote the following simple function that generates a BATCH file:
function [] = Generate_Batch_File(Fullpath,Command)
FID = fopen(Fullpath,'w');
fprintf(FID,'echo on\n');
fprintf(FID,'%s',Command);
fclose(FID);
%%
This generates a temporary BATCH file. Running the file succeeds and the C++ program in it runs smoothly with all the command line paraeters. Just pass the command line you want to execute instead of the 'Command' variable and u are set.
Hope this helps
Avner

Stefan Glasauer
Stefan Glasauer 2021-2-27
Similar problem here, but the problem was that calling system or dos caused Matlab to hang:
system('myprogram "hello world"')
never comes back and has to be killed via Ctrl+C. However,
system('myprogram "hello world" &')
does come back, but leaves an open command window, which ispretty annoying when you want to call the program multiple times.
Therefore I also resorted to a batch file, here it is:
myprogram %1
exit
this batch can now be called via
system('mybatch "hello world" &')
runs the program and closes the command window after running.
Perhaps this helps!
  2 个评论
Walter Roberson
Walter Roberson 2021-2-27
system() waits for the process to finish unless you use &
Stefan Glasauer
Stefan Glasauer 2021-2-27
Correct, my problem was that running
myprogram "hello world"
from the commandline works without requesting any input, it returns immediately and shows the command prompt again. But
system('myprogram "hello world"')
never returns. That's why I had to run it with &, then it does come back, but leaves an open command window.

请先登录,再进行评论。


Christoph Rasche
Christoph Rasche 2025-2-10,10:44
I have the same problem, on Windows 11. Everything was running on Windows 10, but when switching to 11, the dos/system functions do not execute the binary anymore. I studied this thread, as well as the other one:
My binary does not depend on any DLLs. It is gcc compiled, no Fortran no MS Visual Studio. It does not call any other programs.
Someone else was suggesting it might be a path problem, but since I get the error value -1.0737e+09 ('Entry Point not Found'), then this is an indication that Matlab tries to operate with the executable. I therefore checked permissions, security, firewall, etc. For example, on Windows 10, the anti-virus system had sometimes classified my program as a potential threat, but run it nevertheless. But Windows 11 does NOT notify me of anything of that sort. Is there a systematic way to find out?
  3 个评论
Christoph Rasche
Christoph Rasche 2025-2-13,15:18
Yes, the program runs in a command window. In Matlab I am in the same folder where the program is located - for convenience. It is simply: dos('progname') or system('progname') without any paths. I tried with full paths, but that returns the same error, meaning, Matlab does try to run the binary.
Image Analyst
Image Analyst 2025-2-13,23:00
So what does dependency Walker say the missing modules are?
Download Dependency Walker and tell it to analyze your executable. It should flag some things that are missing. Some are OK if they're missing, but some you'll need. Tell us what modules are missing. You might try to find them on the internet.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by