Quantum
Quantum8mo ago

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
ioB
ioB8mo ago
what's the usecase by the way?
syhol
syhol8mo ago
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 differently
Stack 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?
Quantum
Quantum8mo ago
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
ioB
ioB8mo ago
the easiest thing would probably be to spawn some programs depending on OS and do some console nonsense
Quantum
Quantum8mo ago
quite possibly. let me take a look at what Syhol suggested
Leokuma
Leokuma7mo ago
Deno.execPath()
Deno.execPath()
ioB
ioB7mo ago
^^^ the correct answer