Open straight-shoota opened 3 days ago
Well, on UNIX exec(2)
distinguishes the executable path from the arg list.
Weirdly, CreateProcessW
on Windows does the same, but in order to search path it must be NULL, and the command be merged with the rest of the args :confused:
Process.new
(and.run
) has two parameters,command
for the command to be executed, andargs
for the arguments.I'm not quite sure what's the reasoning behind this separation. It's been established since the early days of Crystal (https://github.com/crystal-lang/crystal/commit/0b35fa5d688110d898275c9ab145cce93a4faffc) and is probably inherited from Ruby's
Kernel#exec
.In many (most?) other APIs, the equivalent method receives a single list of arguments, where the first one represents the command to execute. This is similar to the way process execution is modeled in Unix.
Process
even uses this representation internally: Thecommand
andargs
parameters are merged into a single array inProcess.prepare_args
. Even on Windows. This internal representation asArray(String)
is additional allocation which is actually just an intermediary: On Unix, the array is mapped to an array of pointers to those strings. On Windows it's mapped to an array of wide strings (Array(Slice(UInt16))
). This intermediate representation should be avoidable.However, we might also want to consider whether the public API could use the single array model where the command is just the first element. I'm not sure if this has any clear benefit expect being more similar to other APIs.
This was breviously mentioned in #9030 before. And I suppose this might have some relevancy the
shell: true
conundrum.