我正在創建一個腳本來包裝jdb(java調試器)。我基本上想要包裝這個過程並代理用戶交互。所以,我希望它:如何在ruby中代理shell進程
- 開始加多寶從我的腳本
- 發送加多寶的輸出到stdout
- 暫停,等待輸入時,加多寶確實
- 當用戶輸入命令,把它傳遞給jdb
此刻我真的想要傳遞給jdb。其原因是使用特定參數初始化進程,並可能在將來添加更多命令。
更新: 這裏有什麼最後我用期待的工作殼:
PTY.spawn("jdb -attach 1234") do |read,write,pid|
write.sync = true
while (true) do
read.expect(/\r\r\n> /) do |s|
s = s[0].split(/\r\r\n/)
s.pop # get rid of prompt
s.each { |line| puts line }
print '> '
STDOUT.flush
write.print(STDIN.gets)
end
end
end
鏈接無效。 – defactodeity
謝謝;我刪除了示例鏈接。如果您發現任何具有示例用法的當前網站,請告訴我。 –