ruby-on-rails - 当数据可用时生成进程并将数据发送到 STDIN
问题描述
我想生成一个进程(golang 二进制文件),捕获它的 STDOUT 并引用我可以随时发送到的 STDIN。在我的情况下,我通过 Websockets 获取数据,并希望将它们传递给生成进程的 STDIN。
我在尝试使用各种方法重用 STDIN 时遇到问题,例如使用PTY.spawn
input = nil
def run
cmd = "app/bins/transcode"
read, write, pid = PTY.spawn(cmd)
input = write
Signal.trap(:WINCH) { write.winsize = STDOUT.winsize }
read.each do |line|
# THis works fine and sends the spawned process' STDOUT over websockets
ActionCable.server.broadcast 'shell_channel', test: line
end
Process.wait(pid)
end
# This is never sent to STDIN of the spawned process
input.puts "hello"
我还尝试对 PTY 和 popen3 使用锁定语法,但都未能接收到 STDIN。
解决方案
推荐阅读
- reactjs - 反应不从更新的环境文件中获取数据
- python - 向 Yelp API 发布请求,要求提供已提供的参数
- javascript - 模拟 axios 时可以为 URL 使用通配符吗?
- angular - 子组件中的选项卡和侧边菜单组合问题
- python - 错误!不支持减号?从输入重量
- pandas - 如何将两列浮点数连接到 int 格式的单列?
- postgresql - Postgresql,在函数中定义框变量
- angular8 - 在 Mat-Table 中使用 renderRows 时遇到问题
- python - 在 Python 中直接将文件下载到文件系统
- swift - 快速自动显示键盘