帮酷LOGO
0 0 评论
文章标签:SYS  文件  OUT  CAL  RED  系统  Redirect  调用  
#
# a ruby script to run a series of system calls,
# and put their output into one file.
#
# Alvin Alexander, DevDaily.com
#
# the output file for your scripts:
@filename ="scripts.out"
# the list of scripts you want to run:
scripts_to_run = [ 'foo1.rb', 
 'foo2.rb'
]
# --------------------------------
# don't change anything below here
# --------------------------------
def write_to_file (s)
 f = File.open(@filename,'a')
 f.puts s
 f.close
end
def get_formatted_time
 t = Time.now
 t_out = t.strftime("%H:%M:%S%p (%m/%d/%Y)")
end
scripts_to_run.each { |s|
 write_to_file"nCalling #{s} at #{get_formatted_time} ..."
 system("jruby.bat #{s} >> #{@filename}")
 write_to_file"Script ended at #{get_formatted_time}."
}

你可以通过更改文件末尾附近的system()调用来调整你自己的需求,

我还向输出文件添加了一些时间格式和打印,因此在Windows系统上运行它时,实际输出看起来像这样:

C:AlRobotStuffTests>type scripts.out
Calling foo1.rb at 12:02:58PM (01/27/2007) ...
foo1
Script ended at 12:02:59PM (01/27/2007).
Calling foo2.rb at 12:02:59PM (01/27/2007) ...
foo2
Script ended at 12:03:01PM (01/27/2007).


文章标签:文件  SYS  系统  CAL  RED  OUT  调用  输出  

Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语