Skip to content

Commit

Permalink
which: pass use_java args, needed for WSL on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Sep 30, 2024
1 parent 2a42857 commit 2b04195
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions +stdlib/which.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function exe = which(filename, fpath)
function exe = which(filename, fpath, use_java)
%% which()
% like Python shutil.which, find executable in fpath or env var PATH
% does not resolve path.
Expand All @@ -8,6 +8,7 @@
arguments
filename (1,1) string {mustBeNonzeroLengthText}
fpath (1,:) string = getenv('PATH')
use_java (1,1) logical = false
end

names = filename;
Expand All @@ -24,7 +25,7 @@
% directory/filename given
for exe = names

if stdlib.is_absolute(exe) && stdlib.is_exe(exe)
if stdlib.is_absolute(exe, use_java) && stdlib.is_exe(exe, use_java)
return
end

Expand All @@ -47,7 +48,7 @@

for p = fpath
exe = stdlib.join(p, name);
if stdlib.is_exe(exe)
if stdlib.is_exe(exe, use_java)
return
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/TestWSL.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function test_is_exe_which_wsl(tc)

tc.verifyTrue(stdlib.is_exe(out), "is_exe() failed to detect WSL executable " + out)

wsl_exe = stdlib.which(out);
wsl_exe = stdlib.which(out, [], true);
tc.verifyNotEmpty(wsl_exe, "which() failed to detect WSL executable " + out)

end
Expand Down

0 comments on commit 2b04195

Please sign in to comment.