How to update a GUI programmatically

2 次查看(过去 30 天)
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.

采纳的回答

Andy S
Andy S 2020-7-17
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:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by