mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 21:10:36 +00:00
19 lines
724 B
Lua
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")
|