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

📄 00 - introduction

📁 O Reilly Ruby Cookbook source code
💻
字号:
def run(command, input='')  IO.popen(command, 'r+') do |io|    io.puts input    io.close_write    return io.read  endendrun 'wc -w', 'How many words are in this string?'         # => "7\n"#---print 'Enter your password for sudo: 'sudo_password = gets.chomprun('sudo apachectl graceful', user_password)#---require 'expect'require 'pty'print 'Old password:'old_pwd = gets.chompprint "\nNew password:"new_pwd = gets.chompPTY.spawn('passwd') do |read,write,pid|  write.sync = true  $expect_verbose = false    # If 30 seconds pass and the expected text is not found, the  # response object will be nil.  read.expect("(current) UNIX password:", 30) do |response|    write.print old_pwd + "\n" if response  end    # You can use regular expressions instead of strings. The code block  # will give you the regex matches.  read.expect(/UNIX password: /, 2) do |response, *matches|    write.print new_pwd + "\n" if response  end  # The default value for the timeout is 9999999 seconds  read.expect("Retype new UNIX password:") do |response|    write.puts new_pwd + "\n" if response  endend#---

⌨️ 快捷键说明

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