Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- if #args < 2 then
- print("Usage: eventlog <logfile> <program> <arguments>")
- return
- end
- local logfile = table.remove(args, 1)
- local program = table.remove(args, 1)
- local log = function(text)
- local file = fs.open(logfile, "a")
- file.writeLine(text)
- file.close()
- end
- local main = coroutine.create(function() shell.run(program, unpack(args)) end)
- log("Started " .. program .. " @ " .. os.clock())
- coroutine.resume(main)
- while coroutine.status(main) ~= "dead" do
- local params = {coroutine.yield()} -- equals os.pullEventRaw()
- local event = table.remove(params, 1)
- log(event .. " @ " .. os.clock() .. ": " .. textutils.serialize(params))
- coroutine.resume(main, event, unpack(params))
- end
- log("Stopped " .. program .. " @ " .. os.clock())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement