Closed miversen33 closed 1 year ago
Additional notes, I also cannot get anything useful from the code snippet provided in uv.pipe
local uv = require("luv")
local fds = uv.pipe({nonblock=true}, {nonblock=true})
local read_pipe = uv.new_pipe()
read_pipe:open(fds.read)
local write_pipe = uv.new_pipe()
write_pipe:open(fds.write)
write_pipe:write("hello")
read_pipe:read_start(function(err, chunk)
assert(not err, err)
print(chunk)
end)
The above code does not fail, it just does nothing. I never see anything print from the read_pipe:read_start
callback which leads me to believe this issue might be related to pipes in general, though I still don't know why they are failing here :/
I have verified that spawn
does start the process (verified by doing, using it to modify my filesystem via mkdir
). However, I cannot get output from the pipes
I believe the biggest problem you're running into is that you don't have a call to uv.run()
at the end of your scripts so the Libuv event loop never runs. This would be enough fix the code in the second comment, but the uv.spawn
example from docs.md
does seem to be broken.
The most up-to-date examples would be from our tests. Here's a relevant uv.spawn
test:
Here's a full adapted version that will work outside our test setup:
local uv = require('luv')
-- set this depending on your OS
local isWindows = false
local stdin = uv.new_pipe(false)
local stdout = uv.new_pipe(false)
local input = "Hello World"
local cmd, args, expectedOutput
if isWindows then
cmd = "cmd.exe"
args = {"/c", "set /p output=&call echo %output%"}
expectedOutput = input .. "\r\n"
else
cmd = "cat"
args = {"-"}
expectedOutput = input
end
local handle, pid
handle, pid = uv.spawn(cmd, {
args = args,
stdio = {stdin, stdout},
}, function (code, signal)
print("exit", code, signal)
uv.close(handle)
end)
print(handle, pid)
uv.read_start(stdout, function (err, chunk)
print("stdout", chunk)
assert(not err, err)
assert(chunk == expectedOutput)
uv.close(stdout)
end)
uv.write(stdin, input)
uv.shutdown(stdin, function ()
uv.close(stdin)
end)
uv.run()
Ahh it was uv.run
that was getting me. There's a blurb about it in the tcp example at the top but I ignored the example as I wasn't interested in socket/network communication. Helps if you fully read the docs I suppose lol.
Thank you!
Hello! I am looking into trying to use luv's implementation of
spawn
but the provided sample code is unusable. When it is run (I've attached the example I am using), I receive the following errorLine 41
Removing this line avoids this error but another is thrown
New line 41
I can't quite pin my finger on what the error is, hoping someone can get me pointed in the right direction.
Useful info
I am having other issues with spawn as well (such as not being able to get stdout from it, it leaving defunct processes, etc) but I think this is due to my misunderstanding of how I am supposed to be using it.
Thanks!