-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for passing stdin to child #106
Conversation
Tests seem to fail because certain linux commands cannot be found on Windows. We can fix this by setting up MinGW on the CI for Windows targets only. Here is how it would look like: - name: Set up MinGW
uses: egor-tensin/setup-mingw@v2
with:
platform: x64
if: ${{matrix.runner-os == 'windows-latest'}} We might also want to set the CC @filiptibell |
cc78af5
to
e1c316f
Compare
Included MinGW installation from lune-org#106 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! I left a few comments then this should be all good 👍
Included MinGW installation from lune-org#106 (comment)
Co-authored-by: Filip Tibell <filip.tibell@gmail.com>
Co-authored-by: Filip Tibell <filip.tibell@gmail.com>
Everything looks good code-wise but the windows tests still seem to fail - any idea why that is? |
Windows includes additional symbols with echo (not just a newline, but other things such as return carriages, etc. IIRC). I'm not exactly sure what they are, and it's kind of difficult for me to debug them either, considering I don't have access to a Windows instance. @SnorlaxAssist Could you help out with this? Char codes of these special characters are |
Windows does include additional symbols, although that isn't the problem. The issue is on windows, you would be executing the command So then you would get something like this
You can do something like this to confirm the execution & below is the -- Passing stdin strings should work
local input = echoMessage
if IS_WINDOWS then
-- Confirm input on Windows.
-- Arg 0 would be default from process.spawn
-- Confirm message input, and execute with a blank 2nd input.
input ..= "\n\n"
end
local stdinChild = process.spawn((((not IS_WINDOWS) and "xargs") or "powershell"), {
"echo",
}, {
stdin = input,
})
--[[
stdout would includes the stdin value I believe, might be an stdout/stdin bug, not too sure
stdout:
1: Hello from child process!
2:
3: Hello from child process!
4:
]]
assert(
... |
Unfortunately, that does not pass either! I don't think it has anything to do with what you previously mentioned as lune literally gets a handle to the process and injects to its stdin, it does not run another shell command to pipe stdin (which may require user input, such as an enter). I think this has something to do with some special chars with codes |
Where exactly are you finding those special characters? I don't see those characters in the test & at the output on a VM. |
tests/process/spawn.luau
Outdated
local stdinChild = process.spawn((((not IS_WINDOWS) and "xargs") or "powershell"), { | ||
"echo", | ||
}, { | ||
stdin = (IS_WINDOWS and (echoMessage .. "\n\n")) or echoMessage, | ||
}) | ||
|
||
assert( | ||
stdinChild.stdout == (((IS_WINDOWS and `{string.char(239)}{string.char(191)}`) or "") .. echoMessage .. "\n"), -- Windows "echo" adds these "escape codes" to strings | ||
"Stdin passing did not return proper output" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try this
local stdinChild = process.spawn(not IS_WINDOWS and "xargs" or "powershell", {
"echo",
}, {
stdin = echoMessage .. (IS_WINDOWS and "\n\n" or ""),
})
local stdinChildOut = stdinChild.stdout
if IS_WINDOWS then
stdinChildOut = stdinChildOut:sub(#stdinChildOut - #echoMessage - 1, #stdinChildOut)
end
assert(
stdinChildOut == echoMessage .. trailingAddition,
"Stdin passing did not return proper output"
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, on CI the output looks like this
1: Hello from child process!
2:
3: Hello from child process!
4:
I assume line 1 is the input & line 3 is the output from child process. and at the end of line 3-4 is \r\n
on windows.
Seems like those latest test changes worked! Could you merge in latest changes from main? EDIT: GitHub let me squash merge without any issues anyway 🎉 thank you once again for the PR! |
This PR adds functionality for passing stdin contents to a child process.
Things to finish before merge:
FromLua
implementation for Process options (Rust)SpawnOptions
type (Luau)Closes #89.