Add Process.new with args instead of command, args#16681
Add Process.new with args instead of command, args#16681straight-shoota merged 6 commits intocrystal-lang:masterfrom
Process.new with args instead of command, args#16681Conversation
| # and wait for it to finish. | ||
| # * `Process.exec` replaces the current process. | ||
| def initialize(args : Enumerable(String), *, env : Env = nil, clear_env : Bool = false, | ||
| input : Stdio = Redirect::Close, output : Stdio = Redirect::Close, error : Stdio = Redirect::Close, chdir : Path | String? = nil) |
There was a problem hiding this comment.
Nice touch to not include the shell argument 👍
Now if we could reduce the duplication between both constructors... Ideally the old one should merely wrap the new one.
There was a problem hiding this comment.
We cannot just make it a wrapper because the new one does not support shell feature.
Refactoring to remove duplication is also not easy because it's an initializer and involves instance variable setup. So I opted to leave it at that for now. It's acceptable to have a bit duplication.
|
Hi, why there is no a ::Process.exec overload which support new format? ::Process.exec(
desired_command.split(" ", remove_empty: true),
env: environment,
chdir: @config.root
)Error: expected argument #1 to 'Process.exec' to be String, not Array(String) Overloads are:
For now, I use like this: argv = ::Process.parse_arguments(desired_command)
::Process.exec(
argv[0],
argv[1..],
env: environment,
chdir: @config.root
)
``` |
|
One more question, if we are remove The expected(correct) result should be: Process.run(["cut", "-d", " ", "-f1", "1.txt"], output: STDOUT, error: STDOUT) But, there is no easy way to convert string into correct Array(String), there are so many quirk cases in the shell, finally, user still need use shell frequently like this: |
|
Maybe... do it in Crystal? File.each_line("1.txt") do |line|
fields = line.split(' ')
print fields[1]?
endPlease, discuss on the forum or under issues. This is only indirectly related to this PR. Thanks. |
okay, never mind, I think the right answer is: ::Process.parse_arguments("cut -d ' ' -f1 1.txt")
But, ::Process.exec(["ls", "-alh", "/home"]) not related to this PR, right? Since we already support Should I create a new issue for this? |
|
|
|
Just a few of my humble thoughts. Is anyone else thinking that we're sacrificing too much just for the sake of portability (specifically for Windows?) In my opinion, if we're running |
RFC 0021: Percent String Array Literal with Interpolation ? |
|
Sry, it's crystal-lang/rfcs#25 |
Implements part of #14773
See crystal-lang/rfcs#21