-
Notifications
You must be signed in to change notification settings - Fork 23
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
Support capturing output for async commands #8
Comments
Fair enough. It is a very specific use case, but a valid one nonetheless. As I have some higher priority tasks for the near future, please feel free to submit a pull request :) |
note: I think you have a typo on the last assert: -std.assert(std.stdout == "Hello world!")
+std.assert(result.stdout == "Hello world!") |
^ good catch; I will update that. |
To be honest, I think it would be really valuable to be able to get the stdout of async commands before you join them... This would allow you to essentially stream shell commands through hush... This would be particularly useful if you are starting a server asynchronously, you can never wait for the join, because it will be waiting forever. Instead, you can monitor the stdout stream and decide that it started successfully with a matching pattern you are looking for, then move on, etc. You could stream logs from a server and filter or format messages in hush on the way out. I recognize this is likely more challenging than just waiting for the async command to finish and then respond with the stdout string, but I think it's a much more powerful and re-usable approach. |
this feature is well supported in nodejs, see code examples:
basically the nodejs approach relies on
suppose hush use similar approach, I can imagine the API usage would be let output = ""
let onExit = function(code)
std.print(code)
end
let onData = function(data)
output = output ++ data
end
let flushData = function()
std.print(output)
end
let handle = &{ echo Hello world! }
handle.pid # process id
handle.stdout # process standard output stream
handle.on("exit", onExit) # register process exit handler
handle.stdout.on("data", onData) # register data chunk handler
handle.stdout.on("end", flushData) # register end of data handler |
According to the docs, only work for non-captured command blocks. It would be really handy to support captured command blocks. Something like:
The text was updated successfully, but these errors were encountered: