socketry / async

An awesome asynchronous event-driven reactor for Ruby.
MIT License
2.05k stars 85 forks source link

Running shell command in an async task? #246

Closed emiltin closed 1 year ago

emiltin commented 1 year ago

What's the best way to run a shell command in an async task? I would like the task to read stdout (perhaps with something like Open3.popen2e) as the command writes to it, so I can complete the task or timeout as needed.

ioquatix commented 1 year ago

With Async 2+ it just works, and you don't need any custom code, it's all non-blocking, including Process.wait et al, reading and writing to the child process (via pipes), etc. Let me know if you run into any issues. Feel free to create one task to read and one to write, etc, depending on your requirements.