Definition: | string s = get_interpreter(bool enquote=false, object mb=machine_bits(), integer plat=platform()) |
Description: |
Returns the full path and filename of a phix executable, eg "C:\\Program Files (x86)\\Phix\\pw.exe",
or "" if no suitable interpreter could be found.
You can find the implementation in builtins\get_interpreter.e (an autoinclude). Note this routine should (forever) be considered incomplete/unscientific/experimental. Every situation/installation/platform is subtly different, and this routine is expected to require more than its fair share of tweaks and adjustments. It is however much better than starting from scratch every time you need something along these lines, and of course any changes are best made in a renamed copy rather than the original, to avoid them being obliterated by installing a new version of phix, and ideally change the entry point in your version to say get_interpreter2(), to avoid any potential confusion. All reasonable changes will be added to the next release, on request. If this routine does not meet your needs, I might suggest that you store and use an explicit path instead, possibly defaulted from this, ie one that might work, but when needed can be overridden by the user in some configuration dialog or plaintext file. Things are usually much simpler when interpreting: there is a valid interpreter readily available in command_line()[1]. However, it also has to work when compiled, and not only on Windows/Linux, 32 and 64 bit, but also when run from anywhere. Obviously, using get_interpreter() is a bad idea if you are planning to release your application as a prebuilt binary. enquote: can be true (1) to add double quotes around results containing spaces. mb: primarily for testing purposes, but there may also be cases where you specifically require a 32 or 64 bit interpreter, for example you might (as I do) only have a 32-bit libcurl.dll, so you need to fire off a 32bit interpreter to download some file with that, even when the main app is 64bit. plat: likewise for testing purposes, only in this case of no practical use for anything else that I can think of. Note that an integer mb is advisory: if you ask for 32bit but all it can find is 64bit, it will return that, and vice versa, but at least it looks thoroughly. Should that be unacceptable, pass {32} or {64} to be more strict about the result. You can also (manually) create some or all of the files (In contrast, plat is never advisory: not that there is any need for it, or any overlap in the filenames it searches for.) It searches the path from command_line(), cropped such that ../Phix/demo/.. -> ../Phix/, and current_dir() if different, plus anything in %PATH% that ends with "phix" or "bin" (case insensitive). On Windows it also searches "C:\\Program Files (x86)\\Phix" and "C:\\Program Files\\Phix". On Linux it also searches %HOME%/phix. |
Example: |
?get_interpreter() -- displays eg "C:\Program Files (x86)\Phix\p.exe" -- or perhaps "/home/pete/phix/phix" on Linux |
See Also: | command_line |