Compiled application not finding files with absolute path

조회 수: 12 (최근 30일)
Daniel Lurcock
Daniel Lurcock 2017년 9월 25일
댓글: Walter Roberson 2017년 9월 25일
Hi, part of my application looks in a text file for a path to some other files to process.
It successfully finds the text file, and extracts a string for an absolute path that I have called 'runPath'. I then complete the path to the file I want, which is in a subfolder called 'InputFiles':
input_file=fullfile(runPath,'InputFiles','myFile.m');
run(input_file);
This all works fine when run in Matlab itself, but not when run as a compiled application.
Any ideas how to resolve this? Is it a limitation in the use of the 'run' function? Thanks very much in advance!
p.s. in the error, the path to the file it cannot find is absolutely correct - the file definitely exists! p.p.s. I'm using a mac, in case that matters...

채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 25일
편집: Walter Roberson 2017년 9월 25일
You would have to have added all of the potential files to the project as part of compiling it (in which case they might as well be in directories relative to the project instead of in absolute paths.) There is no possibility of using run() or eval() to execute arbitrary code that was not compiled in to the project.
  댓글 수: 2
Daniel Lurcock
Daniel Lurcock 2017년 9월 25일
Ah, okay, this is slightly disappointing, but makes complete sense when you think about it... otherwise it would open up the whole power of Matlab to a freely distributable compiled application!
I will amend my code to use textscan to load in the variables instead. Thanks very much for your help.
Walter Roberson
Walter Roberson 2017년 9월 25일
Yes, the distinction between code and data is important here. The code parser does not exist in compiled executables so the compiled executables cannot run arbitrary code -- but you can load data no problem.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by