I am happily launching a program in a windows system from Lua using
strProgram = '"C:\\Program Files\\Ps Pad\\PSPad.exe"'
strCmd = 'start "" '..strProgram
os.execute(strCmd)
This works correctly, launching the program and the script finishing. How ever it flashes up a command window for a fraction of a second, does any one have a way from Lua to launch a program.
Lua's os.execute command is based on the C standard library "shell" function. In Windows, this function will always create a command window, and it will always halt your current process until the window finishes. The latter also happens in Linux.
There is ultimately no way around this. Not through the Lua standard API. Because Lua needs to be light-weight and platform independent, the API is not allowed to use OS-dependent native APIs.
Your best bet would be to use the Lua Ex-Api module. It is effectively abandonware, and you may need to patch up a few compiler issues (I'm guessing the Windows port wasn't their first priority). But it is a reasonably good way to spawn processes. You can choose to wait until it finishes yourself, or let them run in parallel. And it won't throw up a command prompt window, unless the application itself uses one.
This is the piece of code I use to call a batch from Lua, maybe help. In win console (command prompt) open and execute, same in unix (mac|nix)
-- sBatchFile = .bat for windows, .sh for x
function vfFork2(sBatchFile)
local b = package.cpath:match("%p[\\|/]?%p(%a+)")
if b == "dll" then
-- windows
os.execute('start cmd /k call "'..sBatchFile..'"')
elseif b == "dylib" then
-- macos
os.execute('chmod +x "'..sBatchFile..'"')
os.execute('open -a Terminal.app "'..sBatchFile..'"')
elseif b == "so" then
-- Linux
os.execute('chmod +x "'..sBatchFile..'"')
os.execute('xterm -hold -e "'..sBatchFile..'" & ')
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With