mirror of
https://github.com/lune-org/lune.git
synced 2025-04-08 04:20:54 +01:00
21 lines
620 B
Lua
21 lines
620 B
Lua
local process = require("@lune/process")
|
|
|
|
-- Should be able to write and read from child process streams
|
|
|
|
local msg = "hello, world"
|
|
|
|
local catChild = process.spawn("cat")
|
|
catChild.stdin:write(msg)
|
|
assert(
|
|
msg == buffer.tostring(catChild.stdout:read(#msg)),
|
|
"Failed to write to stdin or read from stdout of child process"
|
|
)
|
|
|
|
local echoChild = if process.os == "windows"
|
|
then process.spawn("echo", { msg, "2>&1" }, { shell = "cmd" })
|
|
else process.spawn("echo", { msg, ">>/dev/stderr" }, { shell = true })
|
|
|
|
assert(
|
|
msg == buffer.tostring(echoChild.stderr:read(#msg)),
|
|
"Failed to read from stderr of child process"
|
|
)
|