Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to escape whitespace in Node-RED exec node command

Situation:

In my Node-RED flow there is a call to another program where I use the exec node. The arguments are set-up in a function node and passed as the msg.payload to the exec node. This works fine and returns the expected results as long as the command has no space in it.

Problem:

A customer cannot use the call to the command on his system, because the path tp the installation of the program contains a whitespace.

What I tried and didn't work:

  1. Escaping the whitespace with ^ as read in another question: /opt/path^ toProgram^ directory/program
  2. Escaping the whitespace with \\: /opt/path\\ toProgram\\ directory/program
  3. Quoting the whole string with "": "/opt/path toProgram directory/program"
  4. Quoting the whole string and escaping the whitespace: "/opt/path\\ toProgram\\ directory/program"
  5. Quoting the whole string with '': '/opt/path toProgram directory/program'
  6. Leaving the command line empty/""and combining any of the above points with its arguments to one string (in the function node that sets up the arguments for that exec node) and passing it on as the msg.payload -> input parameters in the exec node config panel. No Success.

What's not the problem:

  • The program itself works fine, on mine and on the customers system, it's only the path that is different

  • Other than that specific command string with whitespace, the configuration of the exec node and its msg.payload ( = input parameters or arguments) as well as the "use spawn() instead of exec()?" is fine and works

Request

Is there any other way to escape the whitespace that I'm not aware of so the path to the program can be found? From my understanding the whitespace is interpreted as a separator for the input arguments, which it should be, but not on the command string. This should be a quick fix in my opinion, however nothing seems to work that usually works in node, js, php or bash.. thanks in advance for any hints and ideas!

Environment:

Node-RED version: v0.15.2 | Node.js version: v5.12.0 | Mac OS X 10.11.6 = Darwin 15.6.0 x64 LE

Screenshots

This is the part of the flow: flow excerpt

This config works:command without whitespace

This config does not work: command with whitespace

like image 436
hreimer Avatar asked Jun 10 '26 13:06

hreimer


1 Answers

I've just tested this and option 3 (Quoting the path with "") works fine.

Putting "/home/foo/foo bar/date" in the command section of the exec node executed the binary correctly

like image 178
hardillb Avatar answered Jun 12 '26 06:06

hardillb