12/29/2023 0 Comments Ruby runner to execute scriptrescue is a great way to shoot yourself in the foot, and debugging raised exceptions that could be generated by many lines of code can be a pain. When using a begin/ rescue/ end, try to keep them as small as possible, at least until you're more familiar with how they work.In "real life", AKA, production, you should be even more discerning and capture only the exceptions you expect, but that's a different discussion. Instead of using a bare rescue, your code should at least capture the exception using rescue => e so you can output what occurred.Instead, you should tell the OS to load and run the code in a sub-shell using system, not in the context of your currently running code. You used load but I don't think that's really what you'd want to do.Well, they can, but there are better, more idiomatic, ways. block and end are used to start exception handling, not to define control loops.To make each run have different arguments (given that they are read from the ARGV variable), you need to override the ARGV variable: (1.6).each do |i|ĪRGV = ["cmd_line_arg_#' cannot be loaded, it may have been moved or not exist." You can use load to run the script you need (the difference between load and require is that require will not run the script again if it has already been loaded). #You may change the contents of cmd like you would run it from the command line like ruby /filename You may want to use open3 require 'open3' Beware of pipe duplication in subprocesses.A Dozen (or so) Ways to Start Subprocesses in Ruby: Part 3. ![]() A Dozen (or so) Ways to Start Subprocesses in Ruby: Part 2.A Dozen (or so) Ways to Start Subprocesses in Ruby: Part 1.Running another ruby script from a ruby scriptĪvdi Grimm wrote a series of articles on the Devver blog about different ways to start Ruby subprocesses last summer:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |