使用 ruby 递归运行目录中的文件
我现在正在编写脚本,它必须运行目录及其子文件夹中的每个 ruby 脚本。
例如
run-all.rb
- scripts
- folder1
- script1.rb
- script2.rb
- folder2
- script3.rb
- script4.rb
,由于服务器是 Windows 服务器,我通常会使用批处理文件,但首席开发人员坚持认为一切都必须在 ruby 中完成,因为一些成员拥有 Mac,可能不理解 Windows 批处理文件。
正如这个问题可能已经暴露的那样,我对 Ruby 的了解非常基础。
I'm working on script right now which has to run each ruby script in a directory and its subfolders.
e.g.
run-all.rb
- scripts
- folder1
- script1.rb
- script2.rb
- folder2
- script3.rb
- script4.rb
As the server is a Windows server I would normally use a batch file but the head dev insists everything must be done in ruby as some members have Macs and may not understand Windows Batch Files.
As the question may have given away, my knowledge of Ruby is very basic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
取决于你所说的“运行”是什么意思。 要只执行同一个 ruby 进程中每个脚本中的代码,这可以解决问题:
但是如果您想在它自己的 ruby 进程中运行每个脚本,那么请尝试以下操作:
只需将其中一个放入以下内容中
run-all.rb
和 runruby run-all.rb
构成命令行。Depends what you mean by "run". To just execute the code that is in each script within the same ruby process, this will do the trick:
But it you want to run each script in it's own ruby process, then try this:
Just put the either of these in the contents of
run-all.rb
and the runruby run-all.rb
form the command line.像这样的东西可能应该有效:
Something like this should probably work: