Run exe file with spaces in the filename using Win Command

I’m trying to run an exe with a space in the filename using the Win Command module.

For example ‘filenames with spaces.exe’

I have other playbooks that use win command to run exe files, but those files don’t have spaces in the filename, but this isn’t an option for this particular scenario unfortunately.

I’ve tried a bunch of things (single quotes, double quotes, single and double quotes, double double quotes, etc.) but I just keep getting an error.

Wondering if anyone else has run into this problem and if so, how it was resolved.

Thanks in advance!

Hi,
You can try escaping or store the file names in register and pass register through loop to run your executable files.

//Vinoth

If the path to the executable has a space you need to quote it, unfortunately yaml makes that a bit more difficult as whatever quote you start the value on you also need to end with that quote. There are 2 solutions I recommend to you:

  • Wrap the whole value in a single quote and use an inner double quote
  • win_command: ‘“C:\Program Files\Program\some.exe” arg1 arg2 “argument 3”’
  • Use >- as a multiline yaml string
  • win_command: >-
    “C:\Program FIles\Program\some.exe” arg1 arg2 “argument 3”

The first solution is ok for small command lines but the line length gets quite long and hard to read. The latter is quite useful as any newline in the value is just concatenated together with a space. For example the following is the exact same as the 2nd example

  • win_command: >-
    “C:\Program FIles\Program\some.exe”
    arg1
    arg2
    “argument 3”

Thanks!

I ended up just quoting those names in the shell ==> win_command: ‘“file name with spaces.exe”’