西班牙输了,这次世界杯强队的表现真是没话可说了。
Ruby里调用外部程序的方法有三种,
system、
exec、
重音符(`)。
先看一下
system
# Linux
system("rm", "/tmp/file1")
system("rm /tmp/file2")
system("ls -l | hea -n l")
# Windows
system("notepad.exe", "myfile.txt")
system("cmd /c dir", "somefile")
system是无法捕获外部命令的输出的。
exec和system很像,但是exec后边的代码是不会被执行的。
重音符(`),是可以捕获外部命令输出的,也可以写成
%x的形式。
listing = `ls -l`
now = `date`
listing = %x(ls -l)
now = %x(date)
可以使用
fork方法创建新进程,wait和wait2方法用来等待子进程的返回,waitpid和waitpid2可以等待特定的子进程。Windows不支持fork。
pid1 = ford { sleep 5; exit 3 }
pid2 = ford { sleep 2; exit 3 }
Process.wait # 返回 pid2
Process.wait2 # 返回 [pid1, 768],768是经过左偏移的退出状态
pid3 = ford { sleep 5; exit 3 }
pid4 = ford { sleep 2; exit 3 }
Process.waitpid(pid4, Process::WHOHANG) # 返回 pid4
Process.waitpid2(pid3, Process::WHOHANG) # 返回 [pid3, 768]
pid和ppid分别返回当前进程及其父进程的进程ID。可以用kill方法将UNIX式信号发送给进程。
Process.kill(1, pid1) # 把信号1送给pid1
Process.kill("HUP", pid2) # 把信号HUP送给pid2
Process.kill("SIGHUP", pid3) # 把信号SIGHUP送给pid3
Process.kill("SIGHUP", 0) # 把信号SIGHUP送给自己
分享到:
相关推荐
The Ruby Way(第2版) <br>The Ruby Way assumes that the reader is already familiar with the subject matter. Using many code samples it focuses on "how-to use Ruby" for specific applications, either ...
The Ruby Way 第三版(英文版),全书22章,书中包含600多个按主题分类的示例。每个示例都回答了“如何使用Ruby来完成”的问题。 ——Ruby on Rails之父David Heinemeier Hansson倾力推荐!
the ruby way 2ed. the ruby way 2ed.
the ruby way the ruby way
《The Ruby Way 第二版》...“《The Ruby Way (第2版)中文版》在阐述元编程(metaprogramming)等方面尤其出类拔萃,而元编程是Ruby最引人注目的方面之一。” ——Ruby on Rails之父David Heinemeier Hansson倾力推荐!
11.5 时间日期the ruby way.rar
内含以下4个文档: 1、Addison.Wesley.The.Ruby.Way.2nd.Edition.Oct.2006.chm 2、O'Reilly.Learning.Ruby.May.2007.chm 3、Programming Ruby 2e.pdf 4、ruby中文文档.chm
TheRubyWay(Ruby之道)英文版 Addison.Wesley.The.Ruby.Way.2nd.Edition.Oct.2006.pdf
The Ruby Way(处理文件和目录)
the ruby way,ruby 入门经典
Addison Wesley The Ruby Way 2Nd Edition Oct 2006.pdf(英文版)
关于ruby的电子书,CHM格式 《The ruby way》这本书例子比较多!
Ruby is a fully object-oriented, dynamic scripting language which borrows some of the best features from LISP, Smalltalk, Perl, CLU, and other languages, and blends them into a harmonious whole. The ...
Shaw is the author of the popular online books Learn Python the Hard Way, Learn Ruby the Hard Way, and Learn C the Hard Way. He is also the creator of several open source software projects like ...
[Ruby.Programming_向Ruby之父学程序设计(第2版)].(日)高桥征义,(日)后藤裕藏.扫描版(ED2000.COM).pdf ) 带书签
ruby小程序1 ruby小程序1 ruby小程序1 ruby小程序1