LUA Script os.execute not working

Hello!

has anyone sucessfully excuted an external python script via LUA?

my LUA File:

`
function OnStableStudy(studyId, tags, metadata)
local comm = (‘python /home/connew/script.py’)

local Result = os.execute(comm)
print(Result)

end
`

LOG:

`
15:09:09.383954 LuaContext.cpp:103] Lua says: -1

`

I also tried the command with the full Path of Python:

“/usr/bin/python /home/connew/script.py”

but got the same result.

best regards,

Ben

I am executing external python scripts via Lua without problem (on a Windows installation). I pass the full path to python.exe together with the full path to the script and then use os.execute; I also enclose the path and script name in double quotes. I think the problem with your script is that you’re trying to assign the result of os.execute to a variable. My code looks something like this:

`
local comm = (‘C:\python27\python.exe “C:\temp\a_script.py”’)

os.execute(comm)

`

A quick Google search turned on os.execute return value turned this up, which may help you: https://stackoverflow.com/questions/9676113/lua-os-execute-return-value

I hope that helps.

David

Hi David, thanks for the Info

But it still doesnt execute. I just get Errorlevel “-1”, i also tried more simple commands like “du -h” and it doesnt work either.

Does someone have hands-on experience with executing external commands in Orthanc-LUA on an Linux (Debian) environment?

regards,

Ben

Check out the following samples that are part of the Orthanc distribution:

Is the os module part of the embedded Lua interpreter within Orthanc?

I ask, because we’ve had discussions about Lua earlier in this group that indicated that the modules included with the embedded Lua interpreter may be limited.

In my setup, I’m running the Docker installation, which means Orthanc (and its Lua) are running within the context of an Ubuntu container. I find that I can use Ubuntu’s package manager to add additional modules (ex. sql modules to do some database communication in my Lua scripts).

Within the same Linux context, I believe there was a change at some point in Orthanc where the embedded Lua interpreter stopped looking at the host system’s own Lua modules. I was able to get it working again, but I’d have to do some digging to figure out how I did that. It likely had something to do with declaring an environmental variable on my host pointing to the Lua module installation directories - ie. your typical environmental search path.

FYI, in Docker, this is how we enable access to Lua modules installed at the system level:
https://bitbucket.org/osimis/orthanc-builder/src/6527da6515dfe00effcf9af5d3c63ee154549342/docker/orthanc/Dockerfile#lines-7

As complement to Alain’s answer, the “change at some point in Orthanc where the embedded Lua interpreter stopped looking at the host system’s own Lua modules”, is due to the fact that since Orthanc 1.3.2, the Docker images are built upon the Linux Standard Base, which implies that the Lua interpreter is statically linked inside the Orthanc binaries.

The environment variables mentioned by Alain allow to instruct the Lua engine (built-in, statically linked) to use Lua modules (shared libraries) that are provided by the Ubuntu distribution.

This is possible thanks to the fact that the Lua version of Orthanc (as of writing, 5.1.5) is binary compatible with the modules of the Lua version of Ubuntu 16.04 (also, 5.1.5):
http://lua-users.org/wiki/ApplicationBinaryInterface

I hope this clarifies the situation.

Sébastien-

Thanks, Sebastien, for the clarification.

Related to this, in the evolution of the Orthanc Docker images with the migration from Ubuntu 14 to Ubuntu 16, I recall that one or two of the Lua modules I make use of was split out into its own distribution package and I had to add to my apt-get install commands in the Dockerfile preparation. That’s something to keep in mind for those of us making use of system Lua modules within the Orthanc interpreter.