How to determine application exe name at run time?
11 views (last 30 days)
Show older comments
I want to determine the executable file name and path for a Matlab Compiler produced standalone application at run time. The desired result would be similar to mfilename('fullpath') but return the location of the exe file instead.
0 Comments
Accepted Answer
Guillaume
on 10 Mar 2015
On Windows, on a computer with .Net, this may work:
args = System.Environment.GetCommandLineArgs;
fullpath = args(1);
I don't have the matlab compiler, so can't test.
2 Comments
More Answers (1)
Image Analyst
on 10 Mar 2015
See this function. Call it in your code and see what it returns.
% Returns the folder where the compiled executable actually resides.
function [executableFolder] = GetExecutableFolder()
try
if isdeployed
% User is running an executable in standalone mode.
[status, result] = system('set PATH');
executableFolder = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
% fprintf(1, '\nIn function GetExecutableFolder(), currentWorkingDirectory = %s\n', executableFolder);
else
% User is running an m-file from the MATLAB integrated development environment (regular MATLAB).
executableFolder = pwd;
end
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
uiwait(warndlg(errorMessage));
end
return;
0 Comments
See Also
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!