# Exec node output - tostring() broken data

**URL:** <https://discourse.nodered.org/t/exec-node-output-tostring-broken-data/54276>\
**Category:** General\
**Created:** [25 November 2021 14:16 UTC](https://discourse.nodered.org/t/exec-node-output-tostring-broken-data/54276 "2021-11-25T14:16:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![habakuk25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/habakuk25/32/80963_2.png) [@habakuk25](https://discourse.nodered.org/u/habakuk25)\
**Post date:** [25 November 2021 14:16 UTC](https://discourse.nodered.org/t/exec-node-output-tostring-broken-data/54276/1 "2021-11-25T14:16:12Z")

</div>

hello!

I do have a gps interface with a quite complex cmd output:

cgps -s -l s:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c1d796bc0139f3cdc8f45b0083a94e68fd4b65d.png)

when I pout this in the exec node i get a buffer:  
25.11.2021, 15:17:46[node: f7486f94b9ec09ba](http://192.168.6.4:1880/#)msg : Object

object

payload: buffer[2055][raw](http://192.168.6.4: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 … 239]

[240 … 249]

[250 … 259]

[260 … 269]

[270 … 279]

[280 … 289]

[290 … 299]

[300 … 309]

[310 … 319]

[320 … 329]

[330 … 339]

[340 … 349]

[350 … 359]

[360 … 369]

[370 … 379]

[380 … 389]

[390 … 399]

[400 … 409]

[410 … 419]

[420 … 429]

[430 … 439]

[440 … 449]

[450 … 459]

[460 … 469]

[470 … 479]

[480 … 489]

[490 … 499]

[500 … 509]

[510 … 519]

[520 … 529]

[530 … 539]

[540 … 549]

[550 … 559]

[560 … 569]

[570 … 579]

[580 … 589]

[590 … 599]

[600 … 609]

[610 … 619]

[620 … 629]

[630 … 639]

[640 … 649]

[650 … 659]

[660 … 669]

[670 … 679]

[680 … 689]

[690 … 699]

[700 … 709]

[710 … 719]

[720 … 729]

[730 … 739]

[740 … 749]

[750 … 759]

[760 … 769]

[770 … 779]

[780 … 789]

[790 … 799]

[800 … 809]

[810 … 819]

[820 … 829]

[830 … 839]

[840 … 849]

[850 … 859]

[860 … 869]

[870 … 879]

[880 … 889]

[890 … 899]

[900 … 909]

[910 … 919]

[920 … 929]

[930 … 939]

[940 … 949]

[950 … 959]

[960 … 969]

[970 … 979]

[980 … 989]

[990 … 999]

[1000 … 2055]

topic: ""

\_msgid: "ec67773838452185"

when I convert that to string in a functio node with:

```auto
var b=Buffer.from(msg.payload);
var s=b.toString();
var out=s;
msg.payload= out;
return msg;

```

I get:  
e[?1049he[22;0;0te[1;24re(Be[me[4le[?7he[He[2Je(0e[0mlqe[42bke(B  
e(0e[0mxe(B Time:e[18Gn/ae[2;45He(0e[0mxe(B  
e(0e[0mxe(B Latitude: n/ae[3;45He(0e[0mxe(B  
e(0e[0mxe(B Longitude: n/ae[4;45He(0e[0mxe(B  
e(0e[0mxe(B Altitude: n/ae[5;45He(0e[0mxe(B  
e(0e[0mxe(B Speed:e[18Gn/ae[6;45He(0e[0mxe(B  
e(0e[0mxe(B Heading: n/ae[7;45He(0e[0mxe(B  
e(0e[0mxe(B Climb:e[18Gn/ae[8;45He(0e[0mxe(B  
e(0e[0mxe(B Status: NO FIX (0 secs)e[9;45He(0e[0mxe(B  
e(0e[0mxe(B Longitude Err: n/ae[10;45He(0e[0mxe(B  
e(0e[0mxe(B Latitude Err: n/ae[11;45He(0e[0mxe(B  
e(0e[0mxe(B Altitude Err: n/ae[12;45He(0e[0mxe(B  
e(0e[0mxe(B Course Err:e[23Gn/ae[13;45He(0e[0mxe(B  
e(0e[0mxe(B Speed Err:e[23Gn/ae[14;45He(0e[0mxe(B  
e(0e[0mxe(B Time offset: n/ae[15;45He(0e[0mxe(B  
e(0e[0mxe(B Grid Square: n/ae[16;45He(0e[0mxe(B  
e(0e[0mmqe[42bje(Be[Ae(0e[0me(Be[1;46He(0e[0mlqe[32bke(Be[2;46He(0e[0mxe(BPRN: Elev: Azim: SNR: Used: e(0e[0mxe(Be[3;46He(0e[0mxe(B...

Ho can I fix this to get the right string?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 November 2021 14:43 UTC](https://discourse.nodered.org/t/exec-node-output-tostring-broken-data/54276/2 "2021-11-25T14:43:36Z")

</div>

Yes, that is annoying. Isn't there a parameter on the command to make it not output ansi codes? That's the problem you are getting and it would be better to avoid the problem rather than trying to post-fix it.

If you do need to fix, you will need to do some text replace. Look up the syntax for the JavaScript `replace` string function. Note that you will have to use the regular expression version of replace along with a regex global flag since you need to replace multiple entries.

---

<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:** [25 November 2021 15:11 UTC](https://discourse.nodered.org/t/exec-node-output-tostring-broken-data/54276/3 "2021-11-25T15:11:19Z")

</div>

Would you not be better off starting from a slightly more raw basic string interface like `gpspipe`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2021 15:14 UTC](https://discourse.nodered.org/t/exec-node-output-tostring-broken-data/54276/4 "2021-11-25T15:14:08Z")

</div>

I don't think cgps is really intended for this.  
Is this any use to you? [node-red-contrib-gpsd (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-gpsd)

---

<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:** [24 January 2022 15:14 UTC](https://discourse.nodered.org/t/exec-node-output-tostring-broken-data/54276/5 "2022-01-24T15:14:49Z")

</div>

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