Run a command line process
Verified
Added by iNTERFACEWARE
Execute programs and batch files, you can also load results from a directory listing etc.
Source Code
-- change to the temp directory and run a batch file
-- for windows
os.execute('cd C:\\temp')
os.execute('run.bat')
-- alternatively chain the commands together
os.execute('cd C:\\temp && run.bat')
-- for mac/linux
local D = io.popen('cd "My HD/Users/my-user/Downloads/temp"')
os.execute('run.sh')
-- alternatively chain the commands together
local D = io.popen('cd "My HD/Users/my-user/Downloads/temp" ; run.sh')
-- read names of files and directories
-- for windows
local D = io.popen('ls')
local R = D:read('*a')
-- change to a different directory first
local D = io.popen('cd C:\\Downloads\\temp')
local D = io.popen('dir')
-- alternatively chain the commands together
local D = io.popen('cd C:\\Downloads\\temp && dir')
local R = D:read('*a')
-- for mac/linux
local D = io.popen('ls')
local R = D:read('*a')
-- change to a different directory first
local D = io.popen('cd "My HD/Users/my-user/Downloads/temp"')
local D = io.popen('ls')
-- alternatively chain the commands together
local D = io.popen('cd "My HD/Users/my-user/Downloads/temp" ; ls')
local R = D:read('*a')
Description
Execute programs and batch files, you can also load results from a directory listing etc.
Usage Details
Use os.execute() to run command line processes like programs, and batch files. Use io.popen() if you need to read and write to the command line process, for example read the results of a directory listing into Iguana.
How to use the snippet:
- Paste the desired command into your script
- Modify it to suit your requirements