View Full Version : Help with os.execute and win.ShellExecuteEx

December 14th, 2007, 01:41 AM

I have a question regarding these two options to execute a windows exe from lua script. I start a exe file with several parameters and both ways work fine (os.execute and win.shellexecuteex). My Problem is:

1. when I use the os.execute, there is no way to start the exe hidden without any window. But the os.execute delivers me the right error result code I need for further processing.

2. when I use the win.shellexecuteex, I can start the exe hidden (minimized) as I need it. But unfortunately the result does not contain the error code if the exe fails and I cannot process the result.

My Question: Is there a way to start the os.execute hidden or alternativly is there a way to get more detailed error codes with the win.shellexecute?

By the way: I don't want to do this via direct girder actions but only with lua, because I use this code within a web server script which does not referr to the loaded lua file in girder. So using lua code is mandatory.

thanks for help in advance,


Rob H
December 14th, 2007, 02:57 AM
win.ShellExecuteEx() returns a boolean I believe. If the call fails you should be able to retrieve the error code with win.GetLastError()

December 14th, 2007, 06:34 AM
Thanks for your answer. win.ShellExecuteEx delivers 1 - or 0 if the execution fails. In my situation, the executed command does not fail in execution (from os point of view), but it fails in the sence of the wanted result (application point of view). That means windows says "1" which means execution of the tool succeeded. And the tool delivers an error because of application problems. The os.execute does get this application error; winShellExecuteEx does seemingly not.

But I will give this recomendation a try. Thanks so far.

December 14th, 2007, 06:48 AM
tried the win.GetLastError thing. Unfortunately the application internal error does not report in this. Only os.execute shows the corrent result; but I cannot hide/minimize the dos-box ... :(

Rob H
December 14th, 2007, 08:17 AM
win.ShellExecuteEx simply runs the application and returns without waiting for the app to exit, os.execute() blocks waiting for the app to finish.

Rob H
December 14th, 2007, 08:19 AM
You may be able to execute a .cmd file using win.ShellExecuteEx that runs the app and checks the return code from it then uses that to call Girder's event.exe to pass the return code back to Girder.

December 16th, 2007, 09:57 AM
thanks. If the win.shellexecute command is really asynhron and the os.execute is synchron, then I will have to stay at the os.execute. Rather I will look for a tool for my purpose which allows to hide the dos-box by itself.