# Formatting output from the Exec Node?

**URL:** <https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224>\
**Category:** General\
**Created:** [14 June 2019 09:12 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224 "2019-06-14T09:12:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [14 June 2019 09:12 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/1 "2019-06-14T09:12:29Z")

</div>

Hi

I am running the following command via the Exec node (against my Docker instance of NR), and would appreciate some help formatting the output

```auto
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

```

Flow [Code]

```auto
[{"id":"903b1304.eb1308","type":"exec","z":"c8315ed2.dbcb38","command":"","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Docker : Command Line","x":430,"y":1340,"wires":[["66ce0482.9205ac","525be8e6.3d3618","7d305c8.3af20a4"],["790c7035.376038"],["612bf1bf.e2bd48"]]},{"id":"66ce0482.9205ac","type":"debug","z":"c8315ed2.dbcb38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":1300,"wires":[]},{"id":"790c7035.376038","type":"debug","z":"c8315ed2.dbcb38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":1340,"wires":[]},{"id":"612bf1bf.e2bd48","type":"debug","z":"c8315ed2.dbcb38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":1380,"wires":[]},{"id":"d2d2f23e.fc40e","type":"inject","z":"c8315ed2.dbcb38","name":"","topic":"","payload":"pwd","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1260,"wires":[["903b1304.eb1308"]]},{"id":"a3b46341.ef0178","type":"inject","z":"c8315ed2.dbcb38","name":"","topic":"","payload":"ls","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1300,"wires":[["903b1304.eb1308"]]},{"id":"40ba6da0.b4fcdc","type":"inject","z":"c8315ed2.dbcb38","name":"","topic":"","payload":"ls -R | grep \":$\" | sed -e 's/:$//' -e 's/[^-][^\\/]*\\//--/g' -e 's/^/ /' -e 's/-/|/'","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1340,"wires":[["903b1304.eb1308"]]},{"id":"b6cc799f.3122c8","type":"inject","z":"c8315ed2.dbcb38","name":"","topic":"","payload":"find | sed 's|[^/]*/|- |g'","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":1380,"wires":[["903b1304.eb1308"]]},{"id":"525be8e6.3d3618","type":"file","z":"c8315ed2.dbcb38","name":"","filename":"folder-file-paths.txt","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":710,"y":1260,"wires":[["e64bcc18.c18af"]]},{"id":"e64bcc18.c18af","type":"debug","z":"c8315ed2.dbcb38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":890,"y":1260,"wires":[]},{"id":"39eaa007.aa26d","type":"file in","z":"c8315ed2.dbcb38","name":"","filename":"folder-file-paths.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":430,"y":1180,"wires":[["cd009d1a.20756","7d305c8.3af20a4"]]},{"id":"cd009d1a.20756","type":"debug","z":"c8315ed2.dbcb38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":1180,"wires":[]},{"id":"47c0f16a.0b6a9","type":"inject","z":"c8315ed2.dbcb38","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":1180,"wires":[["39eaa007.aa26d"]]},{"id":"7d305c8.3af20a4","type":"ui_text","z":"c8315ed2.dbcb38","group":"53116eb2.9ab5f8","order":2,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":670,"y":1220,"wires":[]},{"id":"53116eb2.9ab5f8","type":"ui_group","z":"","name":"Services","tab":"1485ea90.d4e765","disp":true,"width":"15","collapse":true},{"id":"1485ea90.d4e765","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

Flow [Image]

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

The debug window looks to format the results just right, but there looks to be a charactor limit, so I sadly can't see everything that's returned.

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

So, in an attempt to get around this, I've tried the ui\_text to see the contents via the dashboard (either via a file node or straight to it), but the formatting is all lost ?

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

Any solutions via existing nodes that people can share ?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 June 2019 09:23 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/2 "2019-06-14T09:23:41Z")

</div>

If you pass it to a ui\_template node with:

```auto
<pre ng-bind-html="msg.payload"></pre>

```

Then the line breaks in the output should be preserved.

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [14 June 2019 18:13 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/3 "2019-06-14T18:13:20Z")

</div>

Thanks Nick

> [@knolleary](#):
>
> ```
> 
> ```

Any idea how to trim the leading spaces that are there ?  
That gap is not there in the debug window version ?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2ce6430fca05d39c67c542b4ff8bf57f15b8b82b.jpeg)

---

<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:** [14 June 2019 21:41 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/4 "2019-06-14T21:41:33Z")

</div>

You can pass it through a change node and use the `$trim` function in JSONata to do that.

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [14 June 2019 22:08 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/5 "2019-06-14T22:08:30Z")

</div>

Thanks Julian,

Sadly I’ve not got any real understanding or experience yet with JSONata, how would I apply the $trim to this, it’s obviously not this ..?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bab8390f99e5d12a0e390cc57eaa11c063f25998.jpeg)

Please could you advise

Thanks

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 June 2019 22:10 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/6 "2019-06-14T22:10:09Z")

</div>

use `$trim(payload)` in the 'to' field.

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [14 June 2019 22:19 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/7 "2019-06-14T22:19:03Z")

</div>

Adding the $trim doesn’t seem to help, it hasn’t removed the leading spaces, and it’s actually removed the hierarchical formatting that was there without it.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/fde8137a607ad0a848b4ddb6f5fbf8283e421767.jpeg)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 June 2019 22:25 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/8 "2019-06-14T22:25:32Z")

</div>

The fact I can see `ng-bind-html="msg.payload">` in that screenshot suggests you've modified the ui\_template node and broken it.

What have you got in the ui\_template node at the moment?

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [14 June 2019 22:44 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/9 "2019-06-14T22:44:03Z")

</div>

Yeah, I thought that too, but I don’t recall touching it, here it is below.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/40612c728706d4a57c1ebb04d8820179ca5feb86.jpeg)

---

<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:** [14 June 2019 23:00 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/10 "2019-06-14T23:00:17Z")

</div>

There is something else wrong with your Dashboard page because I've just tried this and it works fine:

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

```auto
[{"id":"4b9693e0.1fe02c","type":"inject","z":"586832c7.9dc7fc","name":"","topic":"","payload":"ls -R | grep \":$\" | sed -e 's/:$//' -e 's/[^-][^\\/]*\\//--/g' -e 's/^/ /' -e 's/-/|/'","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1100,"wires":[["40759824.32e6e8"]]},{"id":"40759824.32e6e8","type":"exec","z":"586832c7.9dc7fc","command":"","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Docker : Command Line","x":390,"y":1000,"wires":[["4fa3a930.5daee8","e5dfe87f.a8eaa8","d8f4fd88.ec3f9"],["e55af9d5.344348"],["30cb5335.33e1bc"]]},{"id":"d8f4fd88.ec3f9","type":"ui_template","z":"586832c7.9dc7fc","group":"94ae0dc2.bf4b","name":"","order":0,"width":0,"height":0,"format":"<pre ng-bind-html=\"msg.payload\"></pre>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":620,"y":1140,"wires":[[]]},{"id":"94ae0dc2.bf4b","type":"ui_group","z":"","name":"TEST","tab":"ab8ebcdd.2a084","disp":false,"width":"12","collapse":false},{"id":"ab8ebcdd.2a084","type":"ui_tab","z":"","name":"TEST","icon":"dashboard","disabled":false,"hidden":false}]

```

Maybe try putting the output on a separate tab. Also check that you don't have any odd CSS being used.

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [15 June 2019 00:15 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/11 "2019-06-15T00:15:49Z")

</div>

Yep, that did it, a new tab on both the configuration part and the dashboard seems to have done the trick. And if I move it back to the old tab, it reintroduces that big gap - very weird !!

Is there a way to purge the CSS on that tab, if that’s the cause ?

---

<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:** [15 June 2019 09:54 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/12 "2019-06-15T09:54:04Z")

</div>

I think that you will have to try moving items from the old to the new tab until you discover what is causing the issue.

Dashboard is great at getting going quickly but not so good for forcing it to do exactly what _you_ want and can be tricky to debug due to the underlying complexity. Reasons that I wrote uibuilder for people like me who wanted a clean sheet to work with but still wanted a node to do the complex parts around comms and making external libraries available.

---

<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:** [15 June 2019 13:33 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/13 "2019-06-15T13:33:08Z")

</div>

Any extra CSS on that tab will have been added by the user in that or another ui\_template, so just needs to be removed from there.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [15 June 2019 14:46 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/14 "2019-06-15T14:46:13Z")

</div>

FYI, if you just want to show the directory structure, you could also use the `tree` command (it's installed on most \*nix systems -- but tbh, i don't know about the RPi or docker). Here is what the output looks like on my NR install directory, dirs only, limited to 2 levels deep:

```auto
$ tree -d -L 2
.
├── lib
│ └── flows
└── node_modules
    ├── abstract-leveldown
    ├── agent-base
    ├── ajv
    ├── ansi-regex
    ├── ansi-styles
    ├── asap
    ├── asn1
    ├── assert-plus
    ├── ast-types
    ├── asynckit
    ├── aws4
    ├── aws-sdk
    ├── aws-sign2
    ├── axios
    ├── backoff
    ├── balanced-match
    ├── base-64
    ├── base64-js
    ├── base64url
    ├── bcrypt-pbkdf
    ├── bindings
    ├── bl
    ├── boom
    ├── brace-expansion
    ├── buffer
    ├── buffer-equal-constant-time
    ├── buffer-from
    ├── bufferutil
    ├── bytes
    ├── camelcase
    ├── camelcase-keys
    ├── caseless
    ├── chalk
    ├── clone
    ├── co
    ├── coffee-script
    ├── combined-stream
    ├── commander
    ├── concat-map
    ├── concat-stream
    ├── core-util-is
    ├── cryptiles
    ├── csprng
    ├── dashdash
    ├── data-uri-to-buffer
    ├── debug
    ├── deep-is
    ├── define-property
    ├── degenerator
    ├── delayed-stream
    ├── depd
    ├── deprecate
    ├── dummy-json
    ├── ecc-jsbn
    ├── ecdsa-sig-formatter
    ├── encoding
    ├── es6-promise
    ├── es6-promisify
    ├── escape-string-regexp
    ├── escodegen
    ├── esprima
    ├── esprima-extract-comments
    ├── estraverse
    ├── esutils
    ├── events
    ├── extend
    ├── extend-shallow
    ├── extract-comments
    ├── extract-zip
    ├── extsprintf
    ├── fast-deep-equal
    ├── fast-json-stable-stringify
    ├── fast-levenshtein
    ├── faye
    ├── faye-websocket
    ├── fd-slicer
    ├── fecha
    ├── file-type
    ├── file-uri-to-path
    ├── follow-redirects
    ├── forever-agent
    ├── form-data
    ├── fs-extra
    ├── ftp
    ├── generate-function
    ├── generate-object-property
    ├── getpass
    ├── get-stdin
    ├── get-uri
    ├── github-api
    ├── googleapis
    ├── google-auth-library
    ├── google-p12-pem
    ├── graceful-fs
    ├── gtoken
    ├── handlebars
    ├── har-schema
    ├── har-validator
    ├── has-ansi
    ├── hasha
    ├── hawk
    ├── hoek
    ├── html-pdf
    ├── http-errors
    ├── http-parser-js
    ├── http-proxy-agent
    ├── http-signature
    ├── https-proxy-agent
    ├── i18next-client
    ├── iconv-lite
    ├── idb-wrapper
    ├── ieee754
    ├── indent-string
    ├── inherits
    ├── ip
    ├── is-accessor-descriptor
    ├── isarray
    ├── isbuffer
    ├── is-buffer
    ├── is-data-descriptor
    ├── is-descriptor
    ├── isexe
    ├── is-extendable
    ├── is-finite
    ├── is-my-ip-valid
    ├── is-my-json-valid
    ├── isomorphic-fetch
    ├── is-property
    ├── isstream
    ├── is-stream
    ├── is-typedarray
    ├── is-url
    ├── jmespath
    ├── jpeg-js
    ├── jsbn
    ├── jsonfile
    ├── jsonpointer
    ├── json-schema
    ├── json-schema-traverse
    ├── json-stringify-safe
    ├── jsonwebtoken
    ├── jsprim
    ├── jwa
    ├── jws
    ├── kew
    ├── kind-of
    ├── klaw
    ├── level-js
    ├── levn
    ├── libxmljs-mt
    ├── libxslt
    ├── lodash
    ├── lodash.includes
    ├── lodash.isboolean
    ├── lodash.isinteger
    ├── lodash.isnumber
    ├── lodash.isplainobject
    ├── lodash.isstring
    ├── lodash.noop
    ├── lodash.once
    ├── log
    ├── lru-cache
    ├── ltgt
    ├── map-obj
    ├── meow
    ├── mime
    ├── mime-db
    ├── mime-types
    ├── minimatch
    ├── minimist
    ├── mkdirp
    ├── moment
    ├── ms
    ├── nan
    ├── netmask
    ├── nforce8
    ├── node-fetch
    ├── node-forge
    ├── node-red-contrib-aws
    ├── node-red-contrib-function-npm
    ├── node-red-contrib-github
    ├── node-red-contrib-google
    ├── node-red-contrib-jira
    ├── node-red-contrib-npm
    ├── node-red-contrib-pdf
    ├── node-red-contrib-salesforce
    ├── node-red-contrib-slack
    ├── node-red-contrib-tesseract
    ├── node-red-contrib-xsltransform
    ├── node-red-node-base64
    ├── node-red-node-data-generator
    ├── node-red-node-google
    ├── node-red-node-swagger
    ├── node-red-node-twilio
    ├── npm
    ├── number-is-nan
    ├── numbro
    ├── oauth-sign
    ├── object-assign
    ├── object-keys
    ├── optimist
    ├── optionator
    ├── options
    ├── os-tmpdir
    ├── pac-proxy-agent
    ├── pac-resolver
    ├── parse-code-context
    ├── pend
    ├── performance-now
    ├── phantomjs-prebuilt
    ├── pinkie
    ├── pinkie-promise
    ├── png.js
    ├── pop-iterate
    ├── precond
    ├── prelude-ls
    ├── process-nextick-args
    ├── progress
    ├── proxy-agent
    ├── proxy-from-env
    ├── pseudomap
    ├── psl
    ├── punycode
    ├── q
    ├── qs
    ├── querystring
    ├── raw-body
    ├── readable-stream
    ├── repeating
    ├── request
    ├── request.orig
    ├── request-progress
    ├── rimraf
    ├── rootpath
    ├── safe-buffer
    ├── safer-buffer
    ├── sax
    ├── scmp
    ├── seedrandom
    ├── semver
    ├── sequin
    ├── setprototypeof
    ├── slack-client
    ├── smart-buffer
    ├── sntp
    ├── socks
    ├── socks-proxy-agent
    ├── source-map
    ├── sshpk
    ├── statuses
    ├── stream-consume
    ├── string_decoder
    ├── stringstream
    ├── string-template
    ├── strip-ansi
    ├── strip-comments
    ├── supports-color
    ├── swagger-ui
    ├── temp
    ├── tesseract.js
    ├── tesseract.js-core
    ├── throttleit
    ├── thunkify
    ├── toidentifier
    ├── tough-cookie
    ├── tunnel-agent
    ├── tweetnacl
    ├── twilio
    ├── type-check
    ├── typedarray
    ├── typedarray-to-buffer
    ├── @types
    ├── uglify-js
    ├── ultron
    ├── unpipe
    ├── uri-js
    ├── url
    ├── utf8
    ├── utf-8-validate
    ├── util-deprecate
    ├── uuid
    ├── verror
    ├── weak-map
    ├── websocket-driver
    ├── websocket-extensions
    ├── whatwg-fetch
    ├── which
    ├── wordwrap
    ├── ws
    ├── xml2js
    ├── xmlbuilder
    ├── xregexp
    ├── xtend
    ├── yallist
    └── yauzl

298 directories

```

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [15 June 2019 22:08 UTC](https://discourse.nodered.org/t/formatting-output-from-the-exec-node/12224/15 "2019-06-15T22:08:53Z")

</div>

Hi, sadly not, it doesn’t look like Tree is part of the Node Red Docker image.

> [@shrickus](#):
>
> you could also use the `tree` command
