function cmd = getMLRDriveMapCmd(mlr,forceMap)
%

%   Copyright 2019 The MathWorks, Inc.

if (isempty(mlr))
    mlr = matlabroot;
end    

if forceMap
    forceArg = 'forcemap';
else
    forceArg = '';
end

mlrCleaned = mlr;
% a drive may already be mapped and mlr may have a form "N:\", which needs the
% trailing "\" removed
if mlrCleaned(end) == '\'
    mlrCleaned = mlrCleaned(1:end-1);
end

util = fullfile(mlr,'bin',computer('arch'),'checkMATLABRootForDriveMap.exe');


%construct a multi-line command that looks similar to this:
%
% call <matlab bin>\checkMATLABRootForDriveMap.exe "<matlab install dir>" <matlab folder name> > mlEnv.txt
% for /f %%a in (mlEnv.txt) do set "%%a"


cmdLine1 = sprintf('call  "%s" "%s" %s > mlEnv.txt\n', util, mlrCleaned, forceArg);
cmdLine2 = 'for /f %%a in (mlEnv.txt) do set "%%a"\n';

cmd = [cmdLine1 cmdLine2];
