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 .)
  • 说明
    注意这里的括号不能省略。

Posted in  | Tags , , ,