Is there a function that returns the full path of currently executing compiled program?

This question is for both Unix and Winodws platforms, but more for Unix.
I have a compiled Matlab program that will be deployed to some path. But I don't know what the path will be during coding. Is there a function I can use to return the full path of the executing program when it's deployed and running?
For example, if the program is deployed to /home/folderA, the function will return '/home/folderA/app.exe'.
Will need this capabilities to locate other files in the same path, etc.
Thanks in advance.

回答 (1 件)

Image Analyst
Image Analyst 2013 年 4 月 22 日
Did you try mfilename? Otherwise, here's a snippet I found in my code:
function [thePath] = ShowPath()
% Show EXE path:
if isdeployed % Stand-alone mode.
[status, result] = system('set PATH');
thePath = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else % Running from MATLAB.
thePath=pwd;
end
return;

2 件のコメント

Bing
Bing 2013 年 4 月 22 日
Thanks for your suggestions. The code snippet works on Windows but not on Unix. So I am looking for something equivalent on Unix.
I tried mfilename('fullpath'). On Unix, this returns the path of the MCR cache (e.g. ~/mcrCache7.17/app...) when running in deployed mode.
Image Analyst
Image Analyst 2013 年 4 月 22 日
Look in that folder. Your executable is probably there. As you may or may not know, the exe you installed is not the exe that actually runs - it's really a self unarchiving package that installs the real exe to some secret folder.

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

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

質問済み:

2013 年 4 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by