n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
45.7k stars 6.36k forks source link

Add format options for stdout from Execute Command nodes #58

Closed 0ptimus closed 4 years ago

0ptimus commented 4 years ago

Hi,

Let's say I have a home directory with three files named "test1", "test2", and "test3" and I add an Execute Command node with the command as "ls ~". The stdout as of now will be one line as "test1 test2 test3". Not sure if this by design or not. Can an option be added to put the output on separate lines or honor UNIX newlines. So would like output to be like:

test1 test2 test3

Thanks to the developer. Liking this project so far BTW .

janober commented 4 years ago

Very sorry for getting back to this so late!

Please post all further questions to: https://community.n8n.io/ I will then also respond much faster! And if you do not get an answer within 24h simply ping me.

There are actualy already new line "\n" characters in the response. Only the UI does not display them in the view (as \n does not create a new line in HTML). But as soon as you use them in an expression you will see that it works like in this example:

{
  "nodes": [
    {
      "parameters": {
        "command": "ls "
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        430,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "files",
              "value": "={{$node[\"Execute Command\"].data[\"stdout\"]}}"
            }
          ]
        }
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        580,
        300
      ]
    }
  ],
  "connections": {
    "Execute Command": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Really have to find a proper solution that the newline characters get displayed also in the UI!

janober commented 4 years ago

Ok just pushed a "fix": https://github.com/n8n-io/n8n/commit/10881b31de280f64bff6a6bfc6059216227efa24

It uses now a different library for the JSON data. That one displays now new-lines correctly. Will be released with the next n8n version.