lune/tests/process/spawn/stdin.luau
2023-10-05 20:53:29 -05:00

19 lines
724 B
Lua

local process = require("@lune/process")
local IS_WINDOWS = process.os == "windows"
-- Windows uses \r\n (CRLF) and unix uses \n (LF)
local echoTrail = if IS_WINDOWS then "\r\n" else "\n"
local echoMessage = "Hello from child process!"
-- When passing stdin to powershell on windows we must "accept" using the double newline
local result = if IS_WINDOWS
then process.spawn("powershell", { "echo" }, { stdin = echoMessage .. "\n\n" })
else process.spawn("xargs", { "echo" }, { stdin = echoMessage })
local resultStdout = if IS_WINDOWS
then string.sub(result.stdout, #result.stdout - #echoMessage - 1)
else result.stdout
assert(resultStdout == echoMessage .. echoTrail, "Stdin passing did not return proper output")