# Execute windows batch file which called another batch file

**URL:** <https://forum.ansible.com/t/execute-windows-batch-file-which-called-another-batch-file/23496>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [January 18, 2017, 5:20pm UTC](https://forum.ansible.com/t/execute-windows-batch-file-which-called-another-batch-file/23496 "2017-01-18T17:20:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gad](https://avatars.discourse-cdn.com/v4/letter/g/b5a626/32.png) [@Gad](https://forum.ansible.com/u/Gad)\
**Post date:** [January 18, 2017, 5:20pm UTC](https://forum.ansible.com/t/execute-windows-batch-file-which-called-another-batch-file/23496/1 "2017-01-18T17:20:06Z")

</div>

Hi  
Im tryin to execute “c:\my files\a.bat”  
which call : “c:\my files\c.bat”

i did try using the raw module like:

raw: “cd "c:\my-files" & "c:\my-files\a.bat"”

but ansible refuse to pipe the sign &  
also tried with "&" but then error appears

how can i cd to a relevant directory and then execute file.bat??

win\_command???

---

<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:** [January 19, 2017, 10:03pm UTC](https://forum.ansible.com/t/execute-windows-batch-file-which-called-another-batch-file/23496/2 "2017-01-19T22:03:51Z")

</div>

Can you just use the full path to the .bat file?

If you need to change the working directory, perhaps just modify the .bat file contents?

Hope this helps,

Jon

---

<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:** [January 19, 2017, 10:03pm UTC](https://forum.ansible.com/t/execute-windows-batch-file-which-called-another-batch-file/23496/3 "2017-01-19T22:03:51Z")

</div>

Can you just use the full path to the .bat file?

If you need to change the working directory, perhaps just modify the .bat file contents?

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Gad](https://avatars.discourse-cdn.com/v4/letter/g/b5a626/32.png) [@Gad](https://forum.ansible.com/u/Gad)\
**Post date:** [January 22, 2017, 6:11am UTC](https://forum.ansible.com/t/execute-windows-batch-file-which-called-another-batch-file/23496/4 "2017-01-22T06:11:43Z")

</div>

i wish  
activate a bat file (windows) has to be from the directory itself.  
i tried to cd with “&” and call the bat in one line

but ansible raw module does not allow to use & sign

בתאריך יום שישי, 20 בינואר 2017 בשעה 00:03:51 UTC+2, מאת J Hawkesworth:

---

<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:** [January 22, 2017, 8:30am UTC](https://forum.ansible.com/t/execute-windows-batch-file-which-called-another-batch-file/23496/5 "2017-01-22T08:30:42Z")

</div>

Perhaps use a PowerShell script to cd and run the .bat file? You can use the script module to send and run the PowerShell script.

Hope this helps,

Jon
