Skip to content

Batch wrapper doesn't run if there is a space in the path and in parameters #731

@valco1994

Description

@valco1994

I'm starting bazelisk with such a command line:

build --remote_download_outputs=all --target_pattern_file "C:\Users\User Name\..."

and it uses a batch script which is also located inside the 'C:\Users\User Name' folder.

I'm getting the following error:

'C:\Users\User' is not recognized as an internal or external command, operable program or batch file.

It happens due to the batch wrapper, everything works fine if I set BAZELISK_SKIP_WRAPPER or remove the wrapper.

I have investigated it and found that syscall.StartProcess() that is called through some intermediate layers from bazelisk's core.runBazel(), specifies both lpApplicationName and lpCommandLine for CreateProcessW WinAPI function. But it's an unreliable way to start a batch script, it works in some simple cases and fails in others, such as the one that I described above.

Batch scripts should be started in the following way according to CreateProcessW documentation:

To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.

It would also be ok to just skip lpApplicationName and Windows would be able to find the interpreter automatically, but unfortunately, the Go standard library doesn't allow to omit exec.Cmd.Path.

So, the only proper way available for us in Go is using cmd.exe explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2We'll consider working on this in future. (Assignee optional)help wantedNeeds help from external contributorstype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions