mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
21 lines
618 B
Lua
21 lines
618 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("cmd.exe", { "/c", "echo", msg, "1>&2" })
|
|
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"
|
|
)
|