⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 09 - controlling a process on another machine.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
require 'rubygems'require 'net/ssh'def run_remotely(command, host, args)  Net::SSH.start(host, args) do |session|        session.process.popen3(command) do |stdin, stdout, stderr|      yield stdin, stdout, stderr    end  endend#---run_remotely('ls -l /home/leonardr/dir', 'example.com', :username=>'leonardr',             :password => 'mypass') { |i, o, e| puts o.read }# -rw-rw-r--    1 leonardr leonardr       33 Dec 29 20:40 file1# -rw-rw-r--    1 leonardr leonardr      102 Dec 29 20:40 file2#---run_remotely('cat', 'example.com', :username=>'leonardr',             :password => 'mypass') do |stdin, stdout, stderr|  stdin.puts 'Line one.'  puts stdout.read  stdin.puts 'Line two.'  puts stdout.readend# "Line one."# "Line two."#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -