# Binary to string

**URL:** <https://discourse.nodered.org/t/binary-to-string/60997>\
**Category:** General\
**Created:** [8 April 2022 18:04 UTC](https://discourse.nodered.org/t/binary-to-string/60997 "2022-04-08T18:04:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [8 April 2022 18:04 UTC](https://discourse.nodered.org/t/binary-to-string/60997/1 "2022-04-08T18:04:38Z")

</div>

I'm trying to get the output of a shell command but I get binary data:

```auto
msg.payload : buffer[238]
buffer[238][raw](http://192.168.0.2:1880/#)
[0 … 9]
[10 … 19]
[20 … 29]
[30 … 39]
[40 … 49]
[50 … 59]
[60 … 69]
[70 … 79]
[80 … 89]
[90 … 99]
[100 … 109]
[110 … 119]
[120 … 129]
[130 … 139]
[140 … 149]
[150 … 159]
[160 … 169]
[170 … 179]
[180 … 189]
[190 … 199]
[200 … 209]
[210 … 219]
[220 … 229]
[230 … 237]

```

As opposed to this which is the actual output from the command:

```auto
[INFO] Registration Status:Registered
[INFO] Channel address:0x0Bc9751eaD170125485f3dD3A2970214aE2F7220
[INFO] Balance: 25.714893 MYST
[INFO] Earnings: 0.504658
[INFO] Earnings total: 3.228151

```

I assume I'm supposed to convert the binary into a string, but don't know how.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [8 April 2022 18:28 UTC](https://discourse.nodered.org/t/binary-to-string/60997/2 "2022-04-08T18:28:49Z")

</div>

Try  
`msg.payload = msg.payload.toString(); return msg;`  
in a function node.

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [8 April 2022 19:36 UTC](https://discourse.nodered.org/t/binary-to-string/60997/3 "2022-04-08T19:36:53Z")

</div>

just what I needed, thanks.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [8 April 2022 20:59 UTC](https://discourse.nodered.org/t/binary-to-string/60997/4 "2022-04-08T20:59:37Z")

</div>

The exec node should try to return a string if possible. So there must be a non-ascii character in the return that caused it to return a binary buffer.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 April 2022 21:00 UTC](https://discourse.nodered.org/t/binary-to-string/60997/5 "2022-04-22T21:00:31Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
