Run exe file with spaces in the filename using Win Command

40 views
Skip to first unread message

david....@bmt.ky

unread,
Aug 20, 2021, 11:30:02 AM8/20/21
to Ansible Project

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!

vinoth kumar

unread,
Aug 20, 2021, 12:13:06 PM8/20/21
to ansible...@googlegroups.com
Hi,
You can try escaping or store the file names in register and pass register through loop to run your executable files.

//Vinoth 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0783e170-1f85-468b-8cb7-a932f9851ffdn%40googlegroups.com.

jbor...@gmail.com

unread,
Aug 22, 2021, 3:19:08 PM8/22/21
to Ansible Project
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"

david....@bmt.ky

unread,
Aug 23, 2021, 11:22:29 AM8/23/21
to Ansible Project
Thanks!

I ended up just quoting those names in the shell ==> win_command: '"file name with spaces.exe"'
Reply all
Reply to author
Forward
0 new messages