Resolving symlinks in lua

1k views Asked by At

I tried googling, but I found only additional packages handling this (which I would like to avoid for various reasons).

In Lua5.3, is there some way to resolve a symlink, possibly recursively, using just the standard library?

I'm looking for something equivalent to:

lua -lfs -e 'print(fs.realink("/proc/self/exe"))'

... only I don't have "fs" (and required "path") on my target.

Any way implementing this in pure lua using just the standard lib?

1

There are 1 answers

0
koyaanisqatsi On

In Lua 5.3 i use...

cmd=function(cmd)
cmd=io.popen(cmd, 'r')
cmd = cmd:read('a+')
return cmd
end

...for storing output of external commands in a Lua variable. An example for using it...

erg=cmd('file /proc/self/exe|grep -o -E "[/a-z]{1,512}$"')
print(erg)

But io.popen() is not available on all Lua 5.3 environments for security reasons. So you have to check this before you can using it.