LUA Script os.execute not working

1,631 views
Skip to first unread message

Benjamin Winkler

unread,
Jun 6, 2018, 9:14:17 AM6/6/18
to Orthanc Users
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

David Platten

unread,
Jun 7, 2018, 3:10:27 AM6/7/18
to Orthanc Users
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

Benjamin Winkler

unread,
Jun 12, 2018, 4:22:41 AM6/12/18
to Orthanc Users

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

Sébastien Jodogne

unread,
Jun 12, 2018, 4:25:27 AM6/12/18
to Orthanc Users

John Roberts

unread,
Jun 12, 2018, 1:54:28 PM6/12/18
to Orthanc Users
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.

Alain Mazy

unread,
Jun 13, 2018, 3:33:06 AM6/13/18
to John Roberts, Orthanc Users
FYI, in Docker, this is how we enable access to Lua modules installed at the system level:

--

Alain Mazy / CTO 
a...@osimis.io / +32 494 31 67 27

Osimis

OSIMIS S.A. 
Rue bois Saint-Jean 15/1BE-4102 Seraing 
www.osimis.io

Twitter LinkedIn


Sébastien Jodogne

unread,
Jun 13, 2018, 4:30:20 AM6/13/18
to Orthanc Users
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-

John Roberts

unread,
Jun 13, 2018, 1:23:29 PM6/13/18
to Orthanc Users
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.
Reply all
Reply to author
Forward
0 new messages