Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install MathLink program with arbitrary PATH environment

Is it possible to use Install[] to start a MathLink program with a custom PATH environment variable?

I am trying to use mEngine to connect Mathematica to MATLAB on Windows. It only works if mEngine.exe is launched when the PATH environment variable includes the path to the MATLAB libraries. Is it possible to modify the PATH for launching this program only, without needing to modify the system path? Or is there another way to launch mEngine.exe?

like image 804
Szabolcs Avatar asked Nov 30 '11 12:11

Szabolcs


1 Answers

@acl's solution to wrap mEngine.exe in a batch file, and temporarily modify the PATH from there, works correctly:

I used this as the contents of mEngine.bat:

set PATH=c:\path\to\matlab\bin\win32;%PATH%
start mEngine.exe %*
  • *% ensures that all command line arguments are passed on to mEngine.exe
  • start is necessary to prevent the command window from staying open until mEngine.exe terminates

It can be started using Install["mEngine.bat"].

Since all the information that is needed for the kernel to communicate with mEngine.exe is passed by Install[] as command line arguments, all we need to do is launch mEngine.exe with these arguments. It is not necessary for Install[] to know the location of mEngine.exe, the important thing is that the process gets launched with the correct command line arguments, which is ensured by %*.

like image 166
Szabolcs Avatar answered Oct 15 '22 14:10

Szabolcs