How to get the path to the compiled binary?
import.meta.url
and Deno.mainModule
are used to get the current script, but after a binary is created, those get frozen to the script at the time that the compile was performed. Moving the binary somewhere else gives you the same (now wrong) result when import.meta.url
or Deno.mainModule
get called.7 Replies
what's the usecase by the way?
One option is to get the pid from
Deno.pid
then using that to lookup the path to the executable https://stackoverflow.com/questions/606041/how-do-i-get-the-path-of-a-process-in-unix-linux it's messy though as you might need to handle each OS differentlyStack Overflow
How do I get the path of a process in Unix / Linux?
In a Windows environment there is an API to obtain the path which is running a process. Is there something similar in Unix / Linux?
Or is there some other way to do that in these environments?
The use case woud be, run the binary and the binary looks for a settings.json file right next to it or looks inside of /data folder for sqlite files, etc.
off the relative path
seems like something that should be doable for any binary
the easiest thing would probably be to spawn some programs depending on OS and do some console nonsense
quite possibly. let me take a look at what Syhol suggested
^^^
the correct answer