Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How to execute an external command?

Command execute external
0
Posted

How to execute an external command?

0

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

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123