- Build a fully-qualified path name to the installed executable on the system and include that in the system() call...if the executable is properly installed so it knows where it's needed stuff is -- copying just an executable to another directory may not get everything it needs, Or
- Build a .bat file that contains commands to set whatever environment the application needs to run -- then call the .bat file from MATLAB instead.
How to properly call system on Windows
38 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Kylie MacFarquharson
il 24 Lug 2021
Modificato: dpb
il 24 Lug 2021
I'm trying to make a project cross platform, it already works on Linux systems.
The main problem I am having is that I need to call an external executable qafm / qafm.exe
On Linux I just put the executable on in ~/bin, which is on the PATH for my user, so running
system('qafm --rest-of-arguments')
works nicely.
For instance
system('qafm')
returns 1 and prints usage to the command window, as I'd expect.
However on windows I am having trouble.
First, I don't know how to set a user specific path, so I just copied the executable qafm.exe to a MATLAB folder.
This isn't some broken rpath or anything though, if I run .\qafm or .\qafm.exe in powershell or cmd in that folder I get the expected usage output.
However, if I run in the same folder in MATLAB R2019b
system('.\qafm')
it returns -1.0737e+09 (Not a valid error code for the program I promise) and prints nothing to the command window.
Any idea what the problem might be?
9 Commenti
Kylie MacFarquharson
il 24 Lug 2021
Modificato: Kylie MacFarquharson
il 24 Lug 2021
dpb
il 24 Lug 2021
That'll work but it seems to me a better way would still be to have the executable on its own rather than adding into a ML directory...but it's your code so your choice on that organization structure.
May as well put it in as an Answer -- that'll indicate to others that watch but may not be around today that there is a solution so that if they're busy don't spend time on Q? that do have at least one acceptable Answer.
As for the other old paths; I grok that; I just would have hoped the older releases would have been cleaned up with the new install -- although I suppose they're needed if one wanted to be able to run older releases as well. I haven't figured out how to keep the license active on them all so while the older installs are still on the system, they're not activated. I suppose if I were to uninstall them, then it would clean things up. But, who knows--I might at some point in the future need one of the earlier releases and have to go figure out the license thingie then... :) As long as "out of sight, out of mind!" I don't guess it hurts too much unless the path reaches whatever its internal length limit is...
Risposta accettata
Kylie MacFarquharson
il 24 Lug 2021
Modificato: dpb
il 24 Lug 2021
3 Commenti
dpb
il 24 Lug 2021
That's what I was suggesting, yes...it's too much grief in CMD. TCC (the JPSoft CMD replacement) would make it trivial exercise, however... :)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown 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!