Comments (3)
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:
Lines 96 to 138 in 9f80386
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()
from luv.
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
from luv.
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!
from luv.
Related Issues (20)
- Unable to `cancel` a `luv_work_ctx_t` handle HOT 16
- Maintain documentation in a machine readable format HOT 12
- segfault on luv_check_handle HOT 5
- segfault on new_thread and worker.queue HOT 8
- clean stale, unused branches HOT 2
- Frequent segfaults in `push_fs_result` HOT 16
- request bind v1.45.0 new features HOT 13
- Change `get_constrained_memory` binding to return `nil` instead of `0`
- `cpu_info` binding might not handle `model` correctly HOT 2
- Release 1.45.0 checklist. HOT 1
- Add `fs_access` test(s)
- request bind v1.46.0 new features
- fs_scandir_next() sometimes returns name but no type HOT 6
- track issues in neovim related with luv HOT 4
- CI failing for LuaJIT v2.1 branch
- process creation segfault HOT 2
- How to pass command line string to uv.spawn? HOT 4
- Do I have to use `uv.run()` to wait async reading file with `fs_read` API? HOT 2
- Question: Is `shutdown` and `close` (use new_pipe with spawn) sync or async? HOT 1
- Question: the arrival order of uv.spawn `on_exit` and `data == nil` in `read_start` callback on Windows 10? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luv.