Ruby代码
4.times do |i|
File.open("temp.rb","w") do |f|
f.puts "def test"
f.puts "#{i}"
f.puts "end"
end
load "temp.rb"
puts test
end
执行结果为:
0
1
2
3
system(“.ruby”)或者load 'another.rb'具体代码如下:
# 返回ls的输出
s=`ls`
cmd= "ls"
s= `#{cmd}`
# 返回true or false
s= system('ls')
cmd= 'ls'
s= system(cmd)
#返回输出
s= %x[uptime]
#用top进程替换当前ruby进程
exec "top"
cmd = 'top'
exec cmd