GUI pwd behavior after deployment

6 ビュー (過去 30 日間)
legendbb
legendbb 2013 年 5 月 16 日
コメント済み: Arif ul Maula 2016 年 3 月 23 日
It looks for me GUI remembers current work folder of development machine at compile time.
Is there a way to disable or walkaround this?
On the target deployed machine (only MCR installed), uigetfile() always starts from the pwd folder of the compiling machine (as long as it exists) otherwise then start from .\
And write file commands if path not specified always goes to the folder.
Printing pwd results give pwd of compiling machine (if exists), otherwise local.
Is it a designed behavior?
Please comment,
  1 件のコメント
legendbb
legendbb 2013 年 5 月 16 日
編集済み: legendbb 2013 年 5 月 16 日
to add to the original:
uigetpath(''); and '.' all refer back to pwd of compiling machine.
The questions can be rephrased to "how to find current work folder" at runtime?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2013 年 5 月 16 日
I do not believe what you said is true. I compile lots of apps all the time and don't observe that. The current folder of the deployed app is neither the current folder of your compiling machine, nor the folder where your deployed app is installed. Your deployed app is actually not the real executable but a self unarchiving file that unpacks the real executable to some strange folder in some bizarre location that you wouldn't expect. Perhaps Kaustubha will explain in more detail - I get tired of explaining this all the time.
What's probably happening in your case is that you have a call to cd() either in your app, or in your startup.m file. Your startup.m file on your development machine gets run when you run the deployed app on the target machine. If you want, you can check the isdeployed flag in your app and set the current folder to the place you want it to be depending on whether it's on the deployed or development machine.
  3 件のコメント
Image Analyst
Image Analyst 2013 年 5 月 17 日
Yes, the startup gets built into the exe and run by your target user. That's why you nee
Read through the discussion by Frederich here: http://www.mathworks.com/matlabcentral/answers/75311#answer_85018 Particularly look at the link to Loren's blog.
Here's a modified version of my startup.m. Feel free to modify with your folders as needed.
% Compiling applications will build in your startup.m file into the executable.
% Do you have a startup.m file that calls addpath? If so, this will cause run-time errors.
% As a workaround, use isdeployed to have the addpath command execute
% only if running from the MATLAB development environment.
try
fprintf(1, 'Beginning to run startup.m . . .\n');
startupMFileWasRun = true;
% userFolder = ctfroot % Initialize
format compact;
userpath('reset');
if(~isdeployed)
% Running in the MATLAB development environment.
% fprintf('Assigning default path...\n');
% restoredefaultpath;
% Add the Utilities folder and all subfolders to the search path.
fprintf('Adding D:/Matlab/work/Utilities to path...\n');
addpath(genpath('D:/Matlab/work/Utilities'));
% Add the Lumenera folder and all subfolders to the search path.
fprintf('Adding C:/Program Files/MATLAB/Lumenera Camera to path...\n');
addpath(genpath('C:\Program Files\MATLAB\Lumenera Camera'));
% Add just the folders that I need.
addpath(genpath('D:/Matlab/Work/3DImageIO'));
addpath(genpath('D:/Matlab/Work/Utilities'));
addpath(genpath('D:/Matlab/Work/Thresholding'));
cd 'D:/Matlab/work'
fprintf('Saving path...\n');
% savepath;
filebrowser; % Won't work with compiled programs.
fprintf('Rehashing toolbox cache...\n');
rehash toolboxcache;
else
userFolder = pwd;
% If you're deploying a compiled executable to a target computer,
% put the folder where you expect that executable will live.
% IMPORTANT NOTE: In order to compile, you will also need to have this folder on YOUR computer,
% so make it before you run the compile command!
userFolder = 'C:/Program Files (x86)/myApp/MATLAB';
% echo on;
fprintf(1, 'Startup.m is attempting to change the current folder to %s . . .\n', userFolder);
if exist(userFolder, 'dir') == 7
cd(userFolder)
fprintf(1, ' SUCCESS! Changed the current folder to %s\n', userFolder);
else
fprintf(1, ' FAILED! Warning: Failed when it tried to change the current folder to the non-existent folder\n%s\n', userFolder);
end
fprintf(1, ' The current folder is now %s\n', pwd);
end
fprintf(1, 'Done running startup.m.\n');
catch ME
% If there's no catch, then a compiled program will just quit completely
% if it encounters an error. Let's use a try/catch to see if we can get
% it to try to continue running the program instead of just aborting.
errorMessage = sprintf('Error running startup.m:\n%s', ME.message);
fprintf(1, '\n%s\n', errorMessage);
end
Arif ul Maula
Arif ul Maula 2016 年 3 月 23 日
And what about if I want to read images from different directories on a different computer (without MATLAB)? How should I add directory to read images from there?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by