How to update a GUI programmatically

2 vues (au cours des 30 derniers jours)
Andy S
Andy S le 17 Juil 2020
Réponse apportée : Andy S le 17 Juil 2020
I'd like to offer the user the opportunity to automatically update a GUI to the latest version. I can check for and download an updated installer if available. The main challenge is to exit the GUI after launching the installer so it can be overwritten. It would be nice to restart the GUI after installation too. The following code doesn't work, because system waits while the installer is running, so the installer can't overwrite the GUI because it's in use.
status = system('GUIInstaller'); %run the installer for the new version
if status==0
% if successfully executed, close application
closereq();
ImaginaryCommandToRestartTheApplication()
end
Is there a way of launching the installer and not waiting for it to complete?
I'm using the Matlab Compiler App to create the installer, so it's not hugely versatile.

Réponse acceptée

Andy S
Andy S le 17 Juil 2020
In framing my question, I realised what I should have been looking for. By placing an ampersand after the command, the system command does not wait. I then studied the command format for Windows cmd, and discovered you can run consecutive commands. So the following code now runs the installer, followed by restarting the app (assumes it's installed in the same location as the original), while closing the original instance:
% find path of executable
if isdeployed % Stand-alone mode.
[~, result] = system('set PATH');
ExecutablePath = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else % Running from MATLAB.
ExecutablePath=pwd;
end
% launch the installer, and then the newly installed GUI, without waiting
system(['GUIInstaller, ' && "', ExecutablePath,'GUIExecutable"',' &']);
closereq();
The code for finding the path of the executable so it can be relaunched came from:

Plus de réponses (0)

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by