-
Notifications
You must be signed in to change notification settings - Fork 4k
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
On Windows, empty args aren't wrapped with quotes, leads to wrong argv #4778
Comments
Interestingly if I spill to a params file, it contains
Which seems backwards - a blank line would have been more useful to parse args from a file, while the empty quotes would have worked in the argv |
Yes, this is definitely a bug.
|
...I should've added that the code is a demonstration of how empty args work on Windows. Apparently FYI here's an essay about cmd.exe quoting rules: https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ |
/cc @meteorcloudy |
I'm not sure about the right priority, so I'm not assigning any. |
I'm taking a look at this. |
Thank you Yun! |
@alexeagle I tried to use @laszlocsomor 's See the following files: execute.bzl:
and BUILD:
The output:
Bazel shows the command is "bazel-out/host/bin/actions_run/print.exe hello", but actually the empty argument is passed correctly because we invoke the binary through system API instead of running in terminal. |
As I explained, this doesn't seem to be a bug in Bazel, so closing. Reopen if it's still a problem. |
I can still reproduce this:
Maybe it's somehow related to nodejs specifically, but if I just run the program like this, I don't see the problem:
|
I debugged this issue again. And found, if I modify bazel/src/main/java/com/google/devtools/build/lib/windows/jni/WindowsProcesses.java Lines 229 to 232 in 1f684e1
to
The nodejs example will have the expected output:
But the C++ example will output:
The reason is different binaries have different command line parser. While the C++ binary treats There is a very interesting article about this: http://daviddeley.com/autohotkey/parameters/parameters.htm Saddly, I don't think there is any good solution from Bazel side, because Bazel doesn't know how the command line will be parsed. :( |
@meteorcloudy : thanks for looking into this issue! What exact command line did Bazel pass to |
Before the change: The first one is able to pass an empty argument to a C++ binary, but not to a nodejs binary. |
Interesting, I also read https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ which doesn't mention empty arguments but does agree that parsing the command line is up to the process.
As you can see, the double quotes do create an empty argument. So I guess the problem is related to how we spawn the nodejs process under Bazel. |
@alexeagle You are absolutely correct! I finally found the bug.
After adding
The output is now correct:
I'll send a fix for this issue. |
Awesome work again @meteorcloudy thank you!! |
I add some empty args with an action, like this
On linux/mac, the program is run with
my_action '' hello
so I parse two arguments.
On windows it's run with
my_action hello
I can make a minimal repro if that's useful
The text was updated successfully, but these errors were encountered: