필터 지우기
필터 지우기

How to update a GUI programmatically

조회 수: 4 (최근 30일)
Andy S
Andy S 2020년 7월 17일
답변: Andy S 2020년 7월 17일
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