How to run standalone application from the folder where it is located?

91 次查看(过去 30 天)
I made a standalone app using matlab app designer. While making package, the default installation folder for package is showing as ProgramFiles or AppData. But I want to run from the local folder only where the app is located in the User PC. Please suggest the way for doing this.

采纳的回答

Image Analyst
Image Analyst 2024-1-23
It sounds like you've discovered that the directory of the app that actually runs is not the same as your executable that you deployed and installed in some folder. That is true, but it's very confusing. You can click on the executable in the target folder however it unpacks the CTF and another executable in some other secret hidden location. If you want that to be the same folder, in Windows, you can set the environment variable MCR_CACHE_ROOT to be "." and it will unpack the stuff to the same folder. Search this forum for MCR_CACHE_ROOT for more detailed discussions.
But you should never assume that any file you want to access in your deployed executable is in the same folder as your executable, even if you install it there. You should ALWAYS use fullfile to build the known, full file name of your file. Otherwise it probably won't be found.
See these links:
Please read Loren's discussion here: Path management in deployed applications.
and

更多回答(2 个)

Taylor
Taylor 2024-1-23
编辑:Taylor 2024-1-23
cd yourLocalFolder;
system("yourApp.exe")
% If your app has additional inputs:
system('"yourApp.exe" arg1 arg2')
% If you don't want to change your working directory
system("fullPath\yourApp.exe")

Hassaan
Hassaan 2024-1-23
Package the App as a Standalone Application:
  • Open your app in MATLAB and use the Application Compiler (deploytool or the Apps tab in newer versions of MATLAB) to package your app.
  • In the Application Compiler, specify all the required files and settings for your app.
Choose the Output Type:
  • In the Application Compiler settings, select the type of output you want. For a local folder execution, you might want to create a "Standalone Application" or a "Web App" depending on your need.
Specify the Output Folder:
  • You can specify the output directory where the packaged app and its executable will be stored. This can be any directory on your computer.
No Installation Setup:
  • When you package the app, MATLAB creates an executable (.exe for Windows) in the specified output folder. This executable can be run directly from its location.
  • Instead of a full installation setup, you can distribute this folder containing the executable and any other necessary files (like MCR, if needed).
Running the App:
  • Users can run the standalone app by directly executing the .exe file from the folder.
  • Ensure that the end users have the necessary MATLAB Runtime installed on their system, which is required for running standalone applications compiled with MATLAB. The MATLAB Runtime version should match the version of MATLAB used for compiling the app.
  • If the MATLAB Runtime is not installed, you can include it in your distribution, or provide instructions for downloading and installing it.
Distribute the Folder:
  • You can compress the folder containing your standalone application and distribute it. Users can then extract it to any location on their PC and run the app directly from there.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  2 个评论
Radhi
Radhi 2024-1-23
Thank you for the detailed response Muhammad. Exactly the same I had done. I think I would have explained the problem with some more details.
The standalone app was generated already as per the above steps you mentioned. Also, the app is stored in a user system in some local folder and is getting excuted by clicking on it. The requirement is: while running the app, it has to read/generate an input/output file and the file need to be taken/put from/in some folder which is also in the same path, where the execute is kept in User system. I am collecting the User system path using the following command, in the script made for the app.
appFolder = fileparts(mfilename('fullpath'))
When running the standalone app, the above path is showing as follows.
"C:\Users\radhi\AppData\Local\Temp\radhi\mcrCache9.11\TestGenT0\TestGenTool", which is not the local folder, where the app is located and the other required folders were set.
If I get the exact local folder and path where the app is stored in the User system, in appFolder, then my problem would be solved.
Hope I have explained my problem to clarity.
Please suggest me the way.
Thank you.
Image Analyst
Image Analyst 2024-1-23
@Radhi you are correct. I don't think this answer is right and is why I added my Answer. Have you read it yet?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Web App Server 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by