Skip to content

Representation of Process arguments #14773

@straight-shoota

Description

@straight-shoota

Process.new (and .run) has two parameters, command for the command to be executed, and args 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 (0b35fa5) 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: The command and args parameters are merged into a single array in Process.prepare_args. Even on Windows.
This internal representation as Array(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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions