Formatting output from the Exec Node?

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

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

Flow [Code]

[{"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]

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.

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 ?

Any solutions via existing nodes that people can share ?

If you pass it to a ui_template node with:

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

Then the line breaks in the output should be preserved.

Thanks Nick

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

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

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 ..?

Please could you advise

Thanks

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

1 Like

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.

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?

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

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

image

[{"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.

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 ?

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.

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.

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:

$ 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
1 Like

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