# Starting a Background Java Process on Windows

**URL:** <https://forum.ansible.com/t/starting-a-background-java-process-on-windows/22268>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [August 10, 2016, 9:15pm UTC](https://forum.ansible.com/t/starting-a-background-java-process-on-windows/22268 "2016-08-10T21:15:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Fisher](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Allen\_Fisher](https://forum.ansible.com/u/Allen_Fisher)\
**Post date:** [August 10, 2016, 9:15pm UTC](https://forum.ansible.com/t/starting-a-background-java-process-on-windows/22268/1 "2016-08-10T21:15:43Z")

</div>

Hello All–

I’m trying to get a couple of jars up and running in the background on some Windows machines. My expected result is at the end of the play I have both jars running with logs for both, and they’re listening on ports 4444 and 24240 respectively. Here’s my tasks:

`

- raw: Start-Process javaw -ArgumentList ‘-jar C:\Users\Administrator\mySweetJar.jar’
- raw: Start-Process javaw -ArgumentList ‘-Dwebdriver.chrome.driver=C:\Windows\System32\chromedriver.exe -jar C:\selenium.jar -browserSessionReuse -browserTimeout 300 -timeout 300000 -maxSession 1 -log C:\Users\Administrator\node.log’  
`

What actually happens is that Ansible reports the commands running successfully:

`  
TASK [Starting MySweetJar…] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /Users/allen.fisher/projects/setup-windows-SUT/playbook.yml:61  
\<XX.XX.XX.XX\> ESTABLISH WINRM CONNECTION FOR USER: administrator on PORT 5985 TO XX.XX.XX.XX  
\<XX.XX.XX.XX\> EXEC Start-Process javaw -ArgumentList ‘-jar C:\Users\Administrator\MySweetJar.jar’  
ok: [XX.XX.XX.XX] =\> {“changed”: false, “invocation”: {“module\_args”: {“\_raw\_params”: “Start-Process javaw -ArgumentList ‘-jar C:\Users\Administrator\MySweetJar.jar’”}, “module\_name”: “raw”}, “rc”: 0, “stderr”: “”, “stdout”: “”, “stdout\_lines”: }

TASK [Starting Selenium…] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /Users/allen.fisher/projects/setup-windows-SUT/playbook.yml:63  
\<XX.XX.XX.XX\> ESTABLISH WINRM CONNECTION FOR USER: administrator on PORT 5985 TO XX.XX.XX.XX  
\<XX.XX.XX.XX\> EXEC Start-Process javaw -ArgumentList ‘-Dwebdriver.chrome.driver=C:\Windows\System32\chromedriver.exe -jar C:\selenium.jar -browserSessionReuse -browserTimeout 300 -timeout 300000 -maxSession 1 -log C:\Users\Administrator\node.log’  
ok: [XX.XX.XX.XX] =\> {“changed”: false, “invocation”: {“module\_args”: {“\_raw\_params”: “Start-Process javaw -ArgumentList ‘-Dwebdriver.chrome.driver=C:\Windows\System32\chromedriver.exe -jar C:\selenium.jar -browserSessionReuse -browserTimeout 300 -timeout 300000 -maxSession 1 -log C:\Users\Administrator\node.log’”}, “module\_name”: “raw”}, “rc”: 0, “stderr”: “”, “stdout”: “”, “stdout\_lines”: }  
`

But the ports are not open, and there are no logs so it’s almost like Ansible is killing the process before it even gets going.

The commands run as I would expect on the box directly. I’ve tried bundling them into a PowerShell script and using the script module to execute the commands, I’ve tried both java.exe and javaw.exe with no success. Does anyone have a way to accomplish what I’m after?

Thanks, Allen

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [August 10, 2016, 11:05pm UTC](https://forum.ansible.com/t/starting-a-background-java-process-on-windows/22268/2 "2016-08-10T23:05:04Z")

</div>

You’re partially right: it’s not Ansible, but WinRM that’s killing the process.

WinRM runs everything under a Windows job object, and that job object gets terminated when the connection is closed (ie, when Ansible finishes that task), which causes all processes spawned under it to be terminated as well.

Ansible 2.2 is scheduled to ship with Windows async support, as well as the win\_command/win\_shell modules, which currently support a “breakaway” parameter to allow you to do exactly what you’re trying to do here (spawn a process that will run longer than the Ansible WinRM session by explicitly breaking away from WinRM’s job object).

If you need to do it sooner than that, you might want to look into the win\_scheduled\_task module, which allows you to run commands/scripts outside the constraints of WinRM.

-Matt

---

<div class="post-metadata">

**Author:** ![Allen\_Fisher](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Allen\_Fisher](https://forum.ansible.com/u/Allen_Fisher)\
**Post date:** [August 12, 2016, 3:19pm UTC](https://forum.ansible.com/t/starting-a-background-java-process-on-windows/22268/3 "2016-08-12T15:19:58Z")

</div>

Thanks, Matt.

What I ended up doing was using NSSM and installing them both as services. That seems to be working well for at least one of them thus far.

Looking forward to async support in 2.2, though.

Allen
