How to execute an external command?
The simplest way is os.execute which works like the C system call; it calls out to the shell to execute shell commands and external programs. The return code of the execution is usually zero for success. io.popen calls a command but returns a file object so you can read the output of the command, if the second argument is ‘r’, but you can also pass input to a command with a second argument of ‘w’. Unfortunately, you don’t get a io.popen2, and you don’t get the return code. There are also two serious weaknesses of these two functions when operating in Windows GUI mode; (a) you will get the dreaded black box flashing from os.execute and (b) io.popen just doesn’t work. A way around this is to use COM via LuaCOM. This is part of Lua for Windows LuaCOM allows you to access the Windows Scripting Host (WSH) objects.
Related Questions
- When I execute a DUP from the command line prompt, I continue to see Windows dialog boxes and pop-up messages. Can I direct the output to the command line prompt console?
- Why doesn the Free Memory display (under eXecute) match the MEM command?
- Why editor doesn execute some command by specified key combination?