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