# Running exe on windows from a batch file

**URL:** <https://forum.ansible.com/t/running-exe-on-windows-from-a-batch-file/25966>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [November 8, 2017, 10:18pm UTC](https://forum.ansible.com/t/running-exe-on-windows-from-a-batch-file/25966 "2017-11-08T22:18:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [November 8, 2017, 10:18pm UTC](https://forum.ansible.com/t/running-exe-on-windows-from-a-batch-file/25966/1 "2017-11-08T22:18:01Z")

</div>

Where is the setup-x86\_64.exe located? By default commands run from win\_command and win\_shell are run in the user’s home directory which means it will be trying to execute **C:\Users\pkmbuilder\setup-x86\_64.exe**. If the exe is located in another directory you will either have to reference the full/relative path from that user’s home directory or change the working directory on the task. To change the working directory to another path (the example is C:\temp) you can set the task as;

`

- win\_command: cmd.exe /c dir  
args:  
chdir: C:\temp  
`

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [November 9, 2017, 12:06am UTC](https://forum.ansible.com/t/running-exe-on-windows-from-a-batch-file/25966/2 "2017-11-09T00:06:05Z")

</div>

Personally, I would bypass the batch file and just call the executable directly like

- name: install Cygwin  
win\_command: C:\Users\pkmbuilder\setup-x86\_64.exe --root C:\cygwin64 --quiet-mode --site [http://cygwin.mirror.constant.com](http://cygwin.mirror.constant.com/) --packages “openssh,rsync,zip,vim,wget”

# Note if you are using an Ansible version before 2.4, change “openssh,rsync,zip,vim,wget” to "openssh,rsync,zip,vim,wget". If you are on 2.4 keep it as it is

This way you aren’t reliant on a file being present on the server and are bypassing cmd which could obfuscate some results. You can also use win\_package but you would need to determine the product id before hand but doing so would give you some idempotency.

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 9, 2017, 7:54pm UTC](https://forum.ansible.com/t/running-exe-on-windows-from-a-batch-file/25966/3 "2017-11-09T19:54:50Z")

</div>

Hey,

Not sure if either of these are the answer but a couple of things you can try..

Try using win\_shell instead of win\_command. I think it may handle args differently (because it is running inside a shell).

Another thing you could try is using with\_items to pass each of the packages you are installing separately, thereby avoiding the comma in your command line. Probably a bit slower but if it works it might be good enough for you to move on to the next thing.

Hope this helps,

Jon
