Control character error arising only after compiling script to an executable.

2 views (last 30 days)
I am using an application that has the user create configuration files through MATLAB scripts. The user then has to encrypt these configuration files into the application's own file format. The encrypter is provided as a group of p-code files and is simply called in the command window with:
encrypt(<filename.m>)
Instead of encrypting each file manually, I wrote a script to loop over all the configuration files and encrypt them. Everything works fine if this script is run from the MATLAB editor. However, if I compile the script using MATLAB Compiler through the "deploytool" command, I get an error which causes the executable to stop running because it can't find all the right p-code files. Below is the error I receive:
Warning: Control Character '\+' is not valid. See 'doc sprintf' for control characters valid in the format string.
I think have a good understanding of what the error means and I believe it would be fixed if the single backslash was replace by a double backslash. The '\+' is referring to the start of the name of a subdirectory located within the p-code encrypter files. This subdirectory contains a p-code function which is required to complete the encryption but obviously this p-code function cannot be called if a previous function cannot cd to this respective directory.
My main question is why this only occurs when trying to run my script as an executable and if there are any methods I can try to remedy this error. I cannot change the encryption process since it is all in p-code so I have had some trouble trying to think of how I can go about this. Any help is appreciated.
  6 Comments
Walter Roberson
Walter Roberson on 18 Aug 2019
Edited: Walter Roberson on 18 Aug 2019
You could deliberately shadow sprintf
varargout = function sprintf(varargin)
if nargin == 0
error('MATLAB:minrhs')
end
if ~ischar(varargin{1}) && ~isstring(varargin{1})
error('MATLAB:badformat_mx')
end
varargin{1} = regexprep(varargin{1}, '\\\+', '\\\\+');
builtin('sprintf', varargin{:});
end
Joe Koszut
Joe Koszut on 18 Aug 2019
I was able to get a slightly modified form of the code above to work. Thank you for the help.

Sign in to comment.

Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!