How to run standalone application from the folder where it is located?
50 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
Image Analyst
le 23 Jan 2024
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:
and
5 commentaires
Jixiong Su
le 5 Août 2024
I got I just need to change the installation path of the exe from %ProgramFiles% to %AppData%, then I will have the permission to save files in the location where the exe is stored.
Image Analyst
le 5 Août 2024
Yeah, if you were using Windows and then installing your program into a subfolder of the Program Files folder, if you were also trying to have your program write your output data to a subfolder of C:\Program Files, then Windows won't allow that. You'd either have to install your program NOT under Program files, or specify your output folder for your output data in some folder not under Program Files.
Remember (if you read the FAQ) the program that installs to a subfolder of Program Files is not really the program. It's like a shell of the program while the actual program gets installed/extracted (when you run the program) in some weird secret location under c:\users (unless you have specified "MCR_CACHE=." as an environment variable, which you probably didn't do). So personally I install my programs under Program Files but then specify my output folder as a subfolder of my data folder, which I'll always have write capability to of course.
That's what I do. You can install your program to %Appdata% and it should work (as long as you're not specifying a folder or, if you are specifying a folder, that it's not a sub folder of Program Files). But I still recommend writing your output results to your data folder, or a subfolder of your data folder, rather than to a subfolder of your executable.
Plus de réponses (2)
Hassaan
le 23 Jan 2024
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 commentaires
Image Analyst
le 23 Jan 2024
@Radhi you are correct. I don't think this answer is right and is why I added my Answer. Have you read it yet?
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!