mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
22 lines
723 B
Text
22 lines
723 B
Text
local process = require("@lune/process")
|
|
|
|
local expected = "Hello from child process!"
|
|
|
|
local options = { stdio = { stdin = expected } }
|
|
local result = if process.os == "windows"
|
|
then process.exec(
|
|
"powershell",
|
|
{ "-Command", "[System.Console]::Write([System.Console]::In.ReadToEnd())" },
|
|
options
|
|
)
|
|
else process.exec("bash", { "-c", "cat" }, options)
|
|
|
|
local resultStdout = result.stdout
|
|
resultStdout = string.gsub(resultStdout, "^%s+", "") -- Trim leading whitespace
|
|
resultStdout = string.gsub(resultStdout, "%s+$", "") -- Trim trailing whitespace
|
|
assert(
|
|
resultStdout == expected,
|
|
"Passing a string to stdin did not return the expected output!"
|
|
.. `\nExpected: {expected}`
|
|
.. `\nReceived: {resultStdout}`
|
|
)
|