- 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.
- 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 offset PATH=c:\windows\system32;c:\windows\system32\Wbemwmic path Win32_SerialPort Get Caption | findstr "COM"wmic path Win32_PnPEntity Get Caption | findstr "COM"
- Change the MATLAB code to not call the 'system' function. Instead, call the bat script. Then, recompile the application.
How do I call external applications via "system" command in standalone apps compiled with MATLAB Compiler?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 26 Mar 2025
Modificato: MathWorks Support Team
il 4 Apr 2025
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"');
Risposta accettata
MathWorks Support Team
il 4 Apr 2025
Modificato: MathWorks Support Team
il 4 Apr 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.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su COM Component Integration in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!