-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Command prompt escaping in Process.quote_windows
#14300
Comments
And the big question that I keep insisting on...
It might be cool to instead expand As for backticks, I don't have much hope of them ever doing anything sensible... |
Sometimes I've been thinking what the shell would be for a hypothetical |
#15111 establishes the use of Reading https://stackoverflow.com/a/4095133 it seems environment variable substitution occurs before the special rules for # only CRT escaping is applied at the moment
# `lpApplicationName` is nil
# `lpCommandLine` is `cmd.exe /c foo.cmd ^%cd^%`
# `foo.cmd` contains `echo %1`
Process.run("cmd.exe", ["/c", "foo.cmd", "^%cd^%"], output: :inherit, env: {"cd^" => "1 && calc.exe"}) Maybe this is why the workaround mentioned in #14536 is necessary? |
We don't need to spend any time thinking what happens in this scenario: Process.run("cmd.exe", ["/c", ...]) (i.e. passing an array of args) because it's complete nonsense in the first place. In #14557 we simply made it so that an equivalent scenario doesn't get created implicitly (in supported scenarios). But if someone spells that out explicitly, that's totally on them. |
I didn't understand, in which way does it establish that? |
Then what about |
|
And it seems in your example you've shown that there actually isn't a way to ensure that an arbitrary string will not result in variable expansion in the Batch syntax. Say we want to pass the literal string Currently we can achieve it like this: `some_process #{Process.quote("%cd%")}` With cmd involved, there's no way to do that. `cmd.exe /c some_process #{quote_batch("%cd%")}` If the |
But hold on - according to the same link, it seems to say that |
From #13567 we know that
Process.quote_windows
, which only performs the opposite ofCommandLineToArgvW
, does not handle metacharacter escaping for the command prompt. We also need both kinds of escaping, and there isn't a one-size-fits-all solution. So I am proposing the following addition to the standard library:Process.quote
is not supposed to be used in platform-specific scenarios, so it doesn't have to expose those new parameters.This still leaves some questions unanswered:
Process.quote
inside a backtick is portable?.quote_windows
also hold for.quote
?The text was updated successfully, but these errors were encountered: