diff --git a/src/engine.jl b/src/engine.jl index 993c4cb..d3c1ae9 100644 --- a/src/engine.jl +++ b/src/engine.jl @@ -17,7 +17,7 @@ mutable struct MSession function MSession(bufsize::Integer = default_output_buffer_size) ep = ccall(eng_open[], Ptr{Void}, (Ptr{UInt8},), default_startcmd) - if ep == C_NULL + if ep == C_NULL Base.warn_once("Confirm MATLAB is installed and discoverable.") if iswindows() Base.warn_once("Ensure `matlab -regserver` has been run in a Command Prompt as Administrator.") @@ -26,9 +26,12 @@ mutable struct MSession end throw(MEngineError("failed to open MATLAB engine session")) end - # hide the MATLAB command window on Windows - iswindows() && ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), ep, 0) - + if iswindows() + # hide the MATLAB command window on Windows and change to current directory + ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), ep, 0) + ccall(eng_eval_string[], Cint, (Ptr{Void}, Ptr{UInt8}), + ep, "try cd('$(escape_string(pwd()))'); end") + end buf = Vector{UInt8}(bufsize) if bufsize > 0 bufptr = pointer(buf)