-
by "command line command" i mean commands like |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I'm on Linux and the following code works just fine for me: require 'os'
os.execute('clear') -- clears terminal. |
Beta Was this translation helpful? Give feedback.
-
You can run command line commands like in Lua, using the 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) |
Beta Was this translation helpful? Give feedback.
-
-- run.nelua
require 'os'
require 'io'
local output_file: filestream
local run = io.popen("nelua code.nelua")
local output = run:read('a')
output_file = io.open("output.txt", "w+")
output_file:write(output)
output_file:flush()
output_file:close()
run:close() -- code.nelua
print("Hello World"
So is there a way to capture the output even if the compilation of the nelua file fails? |
Beta Was this translation helpful? Give feedback.
You can run command line commands like in Lua, using the
os
orio
modules, you could check Lua documentation or tutorials on how to do that. You are probably looking into usingos.execute
in case you want to execute a command without capturing its output, orio.popen
in case you want to capture the output of a command.Here is a small example: