Ruby语言:Ruby程序运行外部程序(二)
Posted by cnruby Fri, 25 Jan 2008 21:39:00 GMT
Ruby语言:Ruby程序运行外部程序(二)
(.^.)说明:这里主要说明面向操作系统的程序代码
(.^.)Windows操作系统
require 'Win32API'
def system(cmd)
sys = Win32API.new "crtdll", "system", ['P'], 'L'
sys.Call cmd
end
system("del ./hello.txt")
(.^.)Linux操作系统程序一
require "Shell"
sh = Shell.new
sh.ls "-al ."
sh.cd "/opt/java"
(.^.)Linux操作系统程序二
require "Shell"
sh = Shell.new
sh.echo("puts 'Hello World!'") > hello.rb
sh.time("ruby hello.rb")



![Validate my RSS feed [Valid RSS]](/blog1/files/valid-rss.png)




