Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Representation of Process arguments #14773

Open
straight-shoota opened this issue Jul 2, 2024 · 1 comment
Open

Representation of Process arguments #14773

straight-shoota opened this issue Jul 2, 2024 · 1 comment

Comments

@straight-shoota
Copy link
Member

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.

@ysbaddaden
Copy link
Contributor

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 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants