# Output on Windows shows carriage return and new line feed

**URL:** <https://forum.ansible.com/t/output-on-windows-shows-carriage-return-and-new-line-feed/22733>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [October 6, 2016, 7:48pm UTC](https://forum.ansible.com/t/output-on-windows-shows-carriage-return-and-new-line-feed/22733 "2016-10-06T19:48:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cory\_Coager](https://avatars.discourse-cdn.com/v4/letter/c/d2c977/32.png) [@Cory\_Coager](https://forum.ansible.com/u/Cory_Coager)\
**Post date:** [October 6, 2016, 7:48pm UTC](https://forum.ansible.com/t/output-on-windows-shows-carriage-return-and-new-line-feed/22733/1 "2016-10-06T19:48:45Z")

</div>

When looking at the output from a Windows host, all of the lines are appended together onto one line. You can see a “\r\n” instead of a new line. Is there an option to fix this for the output so they display as new lines correctly?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [October 6, 2016, 11:54pm UTC](https://forum.ansible.com/t/output-on-windows-shows-carriage-return-and-new-line-feed/22733/2 "2016-10-06T23:54:50Z")

</div>

That sounds like an issue with your SSH terminal.

---

<div class="post-metadata">

**Author:** ![Cory\_Coager](https://avatars.discourse-cdn.com/v4/letter/c/d2c977/32.png) [@Cory\_Coager](https://forum.ansible.com/u/Cory_Coager)\
**Post date:** [October 7, 2016, 1:48pm UTC](https://forum.ansible.com/t/output-on-windows-shows-carriage-return-and-new-line-feed/22733/3 "2016-10-07T13:48:45Z")

</div>

@Dick  
Do you have this working for Windows hosts? Just to be clear, this only happens on Windows hosts. The output from Linux hosts works correctly.

---

<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:** [October 7, 2016, 5:35pm UTC](https://forum.ansible.com/t/output-on-windows-shows-carriage-return-and-new-line-feed/22733/4 "2016-10-07T17:35:23Z")

</div>

There are numerous places where output is displayed- can you be more specific? The only place I’m aware of that attempts to “prettify” output like that is the “ansible” ad-hoc runner, and it works fine for me:

(ansiblev2) mdavis-mac:win-domain mdavis$ ansible winclient-basic -i hosts -m raw -a "Get-ChildItem c:\ "  
winclient-basic | SUCCESS | rc=0 \>\>

Directory: C:\

Mode LastWriteTime Length Name

* * *

d---- 9/9/2015 4:01 PM inetpub  
d---- 1/4/2016 4:04 PM my  
d---- 8/30/2016 10:32 AM new  
d---- 8/30/2016 10:32 AM new2  
d---- 10/7/2015 1:15 PM newpath  
d---- 8/22/2013 8:52 AM PerfLogs  
d-r-- 9/22/2016 3:48 PM Program Files  
d---- 9/2/2016 5:50 PM Program Files (x86)  
d---- 7/5/2016 5:17 PM Python26  
d---- 9/5/2016 9:09 PM temp  
d---- 5/12/2016 3:18 PM tools  
d-r-- 9/23/2016 2:04 PM Users  
d---- 10/6/2016 1:14 PM vagrant  
d---- 8/22/2016 4:10 PM Windows  
d---- 5/16/2016 10:07 PM こんにちは  
-a— 8/8/2016 10:08 AM 104857600 bigfile.txt  
-a— 10/6/2016 1:44 PM 50 bla.inf  
-a— 9/9/2016 4:40 PM 824 out.txt  
-a— 9/2/2016 5:50 PM 233320 pslog.txt  
-a— 9/2/2016 5:50 PM 1992 wrapperlog.txt

---

<div class="post-metadata">

**Author:** ![Cory\_Coager](https://avatars.discourse-cdn.com/v4/letter/c/d2c977/32.png) [@Cory\_Coager](https://forum.ansible.com/u/Cory_Coager)\
**Post date:** [October 7, 2016, 5:45pm UTC](https://forum.ansible.com/t/output-on-windows-shows-carriage-return-and-new-line-feed/22733/5 "2016-10-07T17:45:15Z")

</div>

This would be the output from a Powershell script using ansible-playbook.

---

<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:** [October 10, 2016, 7:21am UTC](https://forum.ansible.com/t/output-on-windows-shows-carriage-return-and-new-line-feed/22733/6 "2016-10-10T07:21:24Z")

</div>

I think I’ve understood the above, this behaviour is to be expected as Ansible expects JSON back from modules.  
Probably simplest way to fix it is to get your script to return json instead of whatever the objects at the end of the powershell pipeline output.

Sometimes doing a

> ConvertTo-Json -Depth 1

is enough, although sometimes you have to use Select to pick the properties you need.

If you have json in your output you can use register and pickout whatever results you need the same as you would if you were using the return object from an any ansible module. Personally I find it more readable to look for {{ results.someattribute.thing }} rather than {{ results.stdout\_lines[4].thing }} especially as often you can’t guarantee that the result you want is at pos 4 in the stdout\_lines array, and you may have to deal with handling whitespace too before you’ve actually got to a string that you can use.

For extra credit of course, turn your script into an ansible module (its really not a lot of extra code), although you’d probably want to think about idempotence for a module in a way which you might not for a script. (As ever it depends what you are trying to achieve - i don’t allways try to make every playbook completely idempotent after all).

Hope this helps,

Jon
