Skip to content

How to run a command line command from a nelua file #142

Answered by edubart
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

You can run command line commands like in Lua, using the os or io modules, you could check Lua documentation or tutorials on how to do that. You are probably looking into using os.execute in case you want to execute a command without capturing its output, or io.popen in case you want to capture the output of a command.

Here is a small example:

require 'os'
require 'io'

-- Run a command, the output will go to terminal `stdout`.
os.execute('ls')

-- Run a command, the output will go to string `out`.
local f = assert(io.popen('ls'))
local out = assert(f:read('a'))
f:close()
print(out)

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Answer selected by edubart
Comment options

You must be logged in to vote
3 replies
@ghost
Comment options

@edubart
Comment options

@ghost
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants