Ruby语言:Ruby程序运行外部程序(三)

Posted by cnruby Sat, 26 Jan 2008 21:53:00 GMT

Ruby语言:Ruby程序运行外部程序(三)

(.^.)说明:这是一个简单的Windows程序实例应用程序。在下面这个程序中,最后一行代码的函数不能使用Ruby语言的system函数。从中可以看到各种方法之间在不同的场合下存在的差异。

(.^.)在Windows系统下启动Rails应用程序的Ruby程序。
require 'Win32API'

def system(cmd)
  sys = Win32API.new "crtdll", "system", ['P'], 'L'
  sys.Call cmd
end

system("d: && cd D:\opt\rails-app && ruby script/server")



________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。
del.icio.us Digg | FURL | Yahoo! My Web 2.0 | Reddit | Blinklist | Fark

Posted in  | Tags , , ,

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")




________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。
del.icio.us Digg | FURL | Yahoo! My Web 2.0 | Reddit | Blinklist | Fark

Posted in  | Tags , , ,

Ruby语言:Ruby程序运行外部程序(一)

Posted by cnruby Thu, 24 Jan 2008 21:10:00 GMT

Ruby语言:Ruby程序运行外部程序(一)

(.^.)软件环境
(.^.)函数system
  • Linux系统实例代码
    system "rm /tmp/hello.txt"
  • Windows实例代码
    system "cmd /c del ./hello.txt"
    system "calc"
  • 说明
    在执行该函数system以后,程序会继续执行之后的代码。
(.^.)函数exec
  • Linux系统实例代码
    system "ls -al /tmp/hello.txt"
  • Windows实例代码
    system "ls -al ./hello.txt"
  • 说明
    在执行该函数exec以后,程序就停止执行之后的代码。
(.^.)函数·
  • Windows和Linux系统实例代码
    ·ls -al .·
  • 说明
    函数·(重音符,在Tab键上面的按钮)能够让我们获得输出结果。
(.^.)函数%x
  • Windows和Linux系统实例代码
    %x(ls -al .)
  • 说明
    注意这里的括号不能省略。



________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。
del.icio.us Digg | FURL | Yahoo! My Web 2.0 | Reddit | Blinklist | Fark

Posted in  | Tags , , ,

Ruby语言:Ruby语言1.9.0 Windows版本几点说明

Posted by cnruby Wed, 26 Dec 2007 23:48:00 GMT

Ruby语言:Ruby语言1.9.0 Windows版本几点说明

  • 说明
    • Ruby语言1.9.0是一款开发版本;
    • Ruby语言1.9.0的Windows系统mswin版本有两个版本:32位和64位;
    • Ruby语言1.9.0的Windows系统mswin版本软件,点击这里或者这里
    • Ruby语言1.9.0的Windows系统mswin版本的第三方软件,点击这里这里。一般而言这些软件包都是需要的。
    • Ruby语言1.9.0与Rails 2.0不兼容的,Rails 2.0与Ruby 1.8.6版本兼容;
  • Windows系统基本安装命令
    mkdir d:\opt\ruby1.9
    SET RUBY_HOME=d:\opt\ruby1.9
    cd d:\opt\ruby1.9
    wget ftp://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/unstable/ruby-1.9.0-0-i386-mswin32.zip
    7za x ruby-1.9.0-0-i386-mswin32.zip
    bin\ruby -v
    bin\irb
  • Windows系统第三方软件包安装方法说明
    • 下载第三方软件包,使用文件名称包含mswin32的文件,如
      wget http://jarp.does.notwork.org/win32/zlib-1.1.4-1-mswin32.zip
    • 解压该下载的软件包,如
      7za x zlib-1.1.4-1-mswin32.zip
    • 复制该软件包的bin目录下的文件至%RUBY_HOME%\bin中,如
      cp bin\. %RUBY_HOME%\bin\.
  • Windows系统第三方软件包清单
    http://jarp.does.notwork.org/win32/openssl-0.9.8d-2-mswin32.zip
    http://jarp.does.notwork.org/win32/pdcurses-2.60-1-mswin32.zip
    http://jarp.does.notwork.org/win32/readline-4.3-2-mswin32.zip
    http://jarp.does.notwork.org/win32/zlib-1.1.4-1-mswin32.zip
    http://jarp.does.notwork.org/win32/pdcurses-2.60-1-mswin32.zip
  • 参考资料



________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。
del.icio.us Digg | FURL | Yahoo! My Web 2.0 | Reddit | Blinklist | Fark

Posted in  | Tags , ,

Older Posts

Older Posts: 1 2 3 ... 19