Skip to content

Commit

Permalink
cd into current directory on Windows (#120)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
musm authored Sep 4, 2017
1 parent 348452a commit a1945a6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/engine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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)
Expand Down

0 comments on commit a1945a6

Please sign in to comment.