Even with array of arguments it feels more handy to do it like:
args = %w[ffprobe -v error -show_entries format=duration
-of default=noprint_wrappers=1:nokey=1] << file
# ^^^ have to shovel (Array#<<) into the array, since we don't have interpolated arrays %W[]
Process.run args
There probably was a reason for choosing the current format, but does it still stand?
What do you think?
Could you demonstrate what you mean, please? I think it’s common to build an argument list somewhere and then pass the result to run the prepared command. Schematically, it could be represented like this:
def build_command_arguments
# ...
end
def run_command
command_arguments = build_command_arguments
Process.run command_arguments
end
Can the current version be beneficial in that case?
I use Tuple whenever it’s possible because Tuple is cheaper than Array.
In this: Process.run command_and_arguments
“command_and_arguments” contains the command to run and the arguments for that command, and the command that will be executed has to be in a defined position in the array. It can’t be anywhere in the array.
I don’t find that very intuitive nor easily readable.
Also, just because some pattern is common in some programming language, does not mean it needs to be present in any language, or be solvable in the same way in any language.
From a semantic point of view, the command to run is simply not the same as the arguments to that command. Especially since the arguments can (and often are) even omitted.
There are basically two modes of how to use Process.run. Either with program name as string and arguments as an array, or the entire command as a string (with shell: true; additional arg array is optional).
You shouldn’t do that. The difference is not really worth much unless the code runs really often and puts a lot of stress on the GC. When running a program, you should just directly use an array, not a tuple. This works out of the box and doesn’t add additional complexity Process.run needs to build an array anyway, so you don’t gain anything.