Fork me on GitHub
#graalvm
<
2021-04-18
>
Ben Sless12:04:56

Is there a straightforward way of getting the generated executable's location at run time?

chrisn15:04:13

(System/getProperty "user.dir") - What happens with that?

borkdude15:04:39

@chris441 He means the executable that is currently being executed. E.g. when you run bb -e '(+ 1 2 3)', you want to see /usr/local/bin/bb or so

chrisn15:04:13

Ah, got it

borkdude15:04:20

Someone in the GraalVM slack told me that Graal has an API for this

borkdude15:04:38

but I haven't found it

borkdude15:04:26

One use case for this is to have an upgrade command so an executable can update itself (not sure if that's a good idea, but exploring the possibilities)

chrisn16:04:31

Does the answer need to be cross platform? What platform is the query on?

chrisn16:04:42

For unix there are PID-related ways to do this.

borkdude16:04:44

yes, cross platform

borkdude16:04:21

ProcessProperties.getExecutableName()
should be somewhere available

borkdude16:04:11

user=> (org.graalvm.nativeimage.ProcessProperties/getExecutableName)
Execution error (Error) at org.graalvm.nativeimage.impl.ImageSingletonsSupport/checkInstalled (ImageSingletonsSupport.java:69).
The class ImageSingletons can only be used when building native images, i.e., when using the native-image command.
:)

borkdude16:04:29

should be able to run this within a graalvm native image

borkdude16:04:52

@lukaszkorecki That's what you asked recently ^

lukasz13:04:08

Yes, that's the one!

borkdude19:04:05

$ ./bb -e '(do (prn (org.graalvm.nativeimage.ProcessProperties/getProcessID)) (org.graalvm.nativeimage.ProcessProperties/exec (fs/path "/bin/bash") (into-array String [""])))'
28122
bash-3.2$ ps aux | grep 28122
borkdude         28124   0.0  0.0  4399112    904 s015  S+    9:23PM   0:00.00 grep 28122
borkdude         28122   0.0  0.0  4431696   1600 s015  S     9:23PM   0:00.03 TERM_SESSION_ID=w2t2p0:5035ECFF-A5DD-4DF9-9A67-6C736151E9AF
What is it called again when a process replaces itself with another process? This is what happens here ^

borkdude19:04:01

Getting the executable name:

$ ./bb -e '(org.graalvm.nativeimage.ProcessProperties/getExecutableName)'
"/Users/borkdude/Dropbox/dev/clojure/babashka/bb"