App Designer standalone app can't find external file
28 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Scotty Mac
am 26 Okt. 2023
Beantwortet: Scotty Mac
am 30 Okt. 2023
I have an App Designer app that includes a text file for calculations. When I debug, it works correctly.
But when I create a 'Standalone Desktop App and install the program, the app can't find the included text file and crashes. I see the included file in the same directory as the .exe file. Here is my code:
% Load the CTP Timing Protocol File for Processing
ctp_tpfilename = 'HB_CTP.txt';
f = fopen(ctp_tpfilename);
data = textscan(f,'%s');
fclose(f);
registers = data{1}(2:2:end);
registers = convertCharsToStrings(registers);
...
Am I missing the path to the file? I dont know the path it is trying, since this is the compiled application. How can I tell it to look in the same directory are the main executable file?
Thanks in advance.
5 Kommentare
Voss
am 27 Okt. 2023
When you compile using deploytool, uncheck the box under "Additional runtime settings" that says "Do not display the Windows Command Shell (console) for execution". This will pop up a console window when the exe runs and any command-line output will go to that console, including the result of fprintf('%s\n',pwd).
Akzeptierte Antwort
Weitere Antworten (2)
chrisw23
am 27 Okt. 2023
Verschoben: Rik
am 27 Okt. 2023
You have to add dependent files manually in the Compiler App Project before building the standalone component. Since there's no path specified, the file is expected beside your app executable. The app will not be executed in the path where it will be started. It's executed (extracted) in a users temp folder. That's where your file is expected to be loaded without a path specified.
...your app path is somewhere here
C:\Users\<userName>\AppData\Local\Temp\<userName>\mcrCache<MatlabRuntimeVersion>\<yourAppName>
5 Kommentare
Voss
am 27 Okt. 2023
That's right, so compiling the txt with the exe is not the way to go.
Typically, I would put some UI components in the app that allow the user to select the file they want to use, i.e., with uigetfile(), and store the full path to the file as an app property or whatever.
Scotty Mac
am 27 Okt. 2023
Bearbeitet: Scotty Mac
am 27 Okt. 2023
2 Kommentare
Voss
am 27 Okt. 2023
How are you running the exe? E.g., just double-clicking on it? Or using a desktop shortcut? Or running it programmatically, e.g., from a Windows/DOS console?
Referring to 'HB_CTP.txt' in the code makes the code look for that file in the working directory, i.e., the directory returned by pwd().
The working directory when the exe starts is the location where the exe is run from. If double-clicking, the working directory is the location of the exe, in which case the code should find the text file, since it is in the same directory. If running the exe some other way, then the working directory may not be the location of the exe, and you can expect the program not to find the text file.
What happens when you run the exe? Do you get an error message about using textscan() with an invalid file identifier?
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!