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.