How can I find the directory containing my compiled application?

51 views (last 30 days)
How can I find the directory containing my compiled application? The CTF data has been extracted into my user Application Data directory, but neither "ctfroot", "matlabroot" nor "pwd" show the actual location of the compiled executable.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Sep 2020
Edited: MathWorks Support Team on 14 Jan 2021
On Windows there are two possible ways to achieve this:
Option 1:
Extract the path from the environment variable PATH, this can be achieved as in the following example:
function currentDir = getcurrentdir
if isdeployed % Stand-alone mode.
[status, result] = system('path');
currentDir = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else % MATLAB mode.
currentDir = pwd;
end
Please note that using the function "getenv" in the above example will not work. You will have to use the "system" command to get the PATH variable that contains the path to the executable as the first entry. This entry gets added automatically at runtime by the stand-alone.
Option 2:
The alternative, on Windows as well as all other supported platforms, would be to use a MEX-file. Attached is an example that illustrates how to locate the compiled executable. To compile the MEX file, please follow the steps detailed on this page of the documentation:
On Mac machines you can use the following workaround to get the path to the directory where your application sits:
if isdeployed && ismac
NameOfDeployedApp = 'MyDeployedApplication'; % do not include the '.app' extension
[~, result] = system(['top -n100 -l1 | grep ' NameOfDeployedApp ' | awk ''{print $1}''']);
result=strtrim(result);
[status, result] = system(['ps xuwww -p ' result ' | tail -n1 | awk ''{print $NF}''']);
if status==0
diridx=strfind(result,[NameOfDeployedApp '.app']);
realpwd=result(1:diridx-2);
else
msgbox({'realpwd not set:',result})
end
else
realpwd = pwd;
end
  1 Comment
Usha Duddu
Usha Duddu on 7 Jun 2016
Hi Raviko
As per my understanding you want to open the excel file that has been packaged as a part of your compiled application using "deploytool".
You could navigate to the path returned by "mcrcachedir" command and then into your specific project folder. You should be able to find the extracted components of your compiled application in that location.
Please contact MathWorks Technical Support for any further assistance.

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!