posix = require("posix")
stringx = require("pl.stringx")
function system(cmd)
local f
local ok = pcall(
function ()
f = assert(io.popen(cmd, "r"))
end
)
if ok then
local s = assert(f:read("*a"))
f:close()
return stringx.strip(s)
else
return nil
end
end
local pid = posix.getpid("pid")
local path = system("ps -o comm= -p " .. pid)
if path then
local symlink = posix.readlink(path)
if symlink then
print("Path (a symlink): " .. path)
print("Symlink refers to: " .. symlink)
else
print("Path (actual file, not a symlink): " .. path)
end
else
print("Cannot determine path: are you running Lua on MVS in non-POSIX mode?")
end