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.