Skip to content

Instantly share code, notes, and snippets.

@scivision
Created October 22, 2021 00:39

Revisions

  1. scivision created this gist Oct 22, 2021.
    37 changes: 37 additions & 0 deletions mingw_octave_path.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    function prepend = mingw_octave_path()
    % for Octave on Windows, it's necessary to prepend MinGW path
    % when running MinGW-compiled executables
    % Also, Matlab with Parallel Toolbox MPIEXEC conflicts with system MPIEXEC,
    % so excise from Path
    %
    % a command is then run like
    %
    % system([prepend, ' ', 'foo.exe'])

    prepend = '';

    if ~ispc, return, end

    if isoctave && ~isempty(getenv('MINGWROOT'))

    syspath = [getenv('MINGWROOT'), pathsep, getenv('PATH')];
    % setenv('PATH', syspath) % does not help
    prepend = ['set PATH=', syspath, ' && '];

    else

    addons = matlab.addons.installedAddons();
    if ~any(addons.Name == "Parallel Computing Toolbox")
    return
    end

    path_orig = split(getenv('PATH'), ';');
    i = contains(path_orig, 'MATLAB'); % Matlab's MPIexec will fail
    path_new = join(path_orig(~i), ';');

    % setenv('PATH', path_new{1}) % does not help
    prepend = "set PATH=" + path_new{1} + " && ";

    end % if

    end % function