mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
This change also improves the unix module, adding a reboot() system call for fun and profit, fixing the execve() api, and a printimage release.
26 lines
570 B
Lua
26 lines
570 B
Lua
-- example of how to run the ls command
|
|
-- and pipe its output to the http user
|
|
local unix = require "unix"
|
|
ls = unix.commandv("ls")
|
|
reader, writer = unix.pipe()
|
|
if unix.fork() == 0 then
|
|
unix.close(1)
|
|
unix.dup(writer)
|
|
unix.close(writer)
|
|
unix.close(reader)
|
|
unix.execve(ls, {ls, "-Shal"})
|
|
unix.exit(127)
|
|
else
|
|
unix.close(writer)
|
|
SetHeader('Content-Type', 'text/plain')
|
|
while true do
|
|
data = unix.read(reader)
|
|
if data ~= "" then
|
|
Write(data)
|
|
else
|
|
break
|
|
end
|
|
end
|
|
unix.close(reader)
|
|
unix.wait(-1)
|
|
end
|