Skip to content

Commit a1945a6

Browse files
authored
cd into current directory on Windows (#120)
On linux starting the MATLAB engine will automatically open in the current working directory. However, Windows has different behavior and this patch manually changes the engine to the current working directory to more closely match the behavior on linux.
1 parent 348452a commit a1945a6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/engine.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mutable struct MSession
1717

1818
function MSession(bufsize::Integer = default_output_buffer_size)
1919
ep = ccall(eng_open[], Ptr{Void}, (Ptr{UInt8},), default_startcmd)
20-
if ep == C_NULL
20+
if ep == C_NULL
2121
Base.warn_once("Confirm MATLAB is installed and discoverable.")
2222
if iswindows()
2323
Base.warn_once("Ensure `matlab -regserver` has been run in a Command Prompt as Administrator.")
@@ -26,9 +26,12 @@ mutable struct MSession
2626
end
2727
throw(MEngineError("failed to open MATLAB engine session"))
2828
end
29-
# hide the MATLAB command window on Windows
30-
iswindows() && ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), ep, 0)
31-
29+
if iswindows()
30+
# hide the MATLAB command window on Windows and change to current directory
31+
ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), ep, 0)
32+
ccall(eng_eval_string[], Cint, (Ptr{Void}, Ptr{UInt8}),
33+
ep, "try cd('$(escape_string(pwd()))'); end")
34+
end
3235
buf = Vector{UInt8}(bufsize)
3336
if bufsize > 0
3437
bufptr = pointer(buf)

0 commit comments

Comments
 (0)