ZioByte
ZioByte

Reputation: 3024

Resolving symlinks in lua

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?

Upvotes: 1

Views: 1433

Answers (1)

koyaanisqatsi
koyaanisqatsi

Reputation: 2813

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.

Upvotes: 1

Related Questions