Notes
- This event is thrown only if the Process.constructor()
redirect
parameter is set totrue
Process:onRedirect(data) event
Event that occurs when the running process outputs data to standard output/error stream.
Parameters
data
A Buffer that contains the data written by the process.
Return value
This event returns no value.Example
//------ This examples spawn a new cmd.exe process
//------ and redirect stdin/stderr output
local console = require "console"
local sysutils = require "sysutils"
local cmd
console.color = "lightcyan"
console.writecolor("green", "Launching cmd.exe (Press CTRL+C to exit)...\n")
console.writecolor("green", "-------------------------------------------\n")
local p = sysutils.Process('cmd.exe')
function p:onRedirect(data)
if cmd then
data = tostring(data):gsub("^"..cmd, "")
end
console.writecolor("white", data)
end
p:spawn()
while not p.terminated do
sleep(200)
cmd = console.readln()
p:write(cmd.."\n")
end