How do I call external applications via "system" command in standalone apps compiled with MATLAB Compiler?

8 vues (au cours des 30 derniers jours)
I use the system function to execute a third-party application (.exe) and a Windows system command in my MATLAB code.
My code works fine in MATLAB Desktop. But after I compile it as a standalone application using MATLAB Compiler, it doesn't work as expected.
As an example, here is my code. I use the Windows wmic command to find COM port object. When the code is compiled, no COM port can be detected.
% Search win 32 serial port object
[~, res1] = system('wmic path Win32_SerialPort Get Caption | findstr "COM"');
% Search win 32 plug and play object (with COM in name)
[~, res2] = system('wmic path Win32_PnPEntity Get Caption | findstr "COM"');

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 4 Avr 2025
Modifié(e) : MathWorks Support Team le 4 Avr 2025
This could be due to DLL conflicting issue. The compiled standalone application execution modifies the Windows Path. The current folder of the .exe file and <MATLAB or MATLABRuntime>\bin\win64 folder are added to the beginning of the PATH environment variable. 
If the system command or the third-party application depends on a DLL library that is also installed in <MATLAB or MALABRuntime>\bin\win64 folder, but the DLL version is incompatible, its execution might error. 
To resolve the issue, one workaround is to reset the PATH environment variable before calling the system command. 
  1. Find out what directories the system command or the third-party application depends on from the PATH environment variable. For the Windows "wmic" tool example we gave above, it depends on C:\Windows\System32 and C:\Windows\System32\Wbem.
  2. Create a bat script that sets the PATH environment variable to the directories identified in Step 1. Then, call the command/third-party application that is called by the system function:
    run_wmic.bat
    -------------------
    @echo off
    set PATH=c:\windows\system32;c:\windows\system32\Wbem
    wmic path Win32_SerialPort Get Caption | findstr "COM"
    wmic path Win32_PnPEntity Get Caption | findstr "COM"
  3. Change the MATLAB code to not call the 'system' function. Instead, call the bat script. Then, recompile the application. 

Plus de réponses (0)

Catégories

En savoir plus sur COM Component Integration dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by