# Exec-Node: Works fine in Linux Terminal, but not in Exec-Node

**URL:** <https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126>\
**Category:** General\
**Tags:** exec\
**Created:** [13 November 2024 16:37 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126 "2024-11-13T16:37:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [13 November 2024 16:37 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/1 "2024-11-13T16:37:29Z")

</div>

Hi,

I use terminal command to control my Samsung Oven mit SmartThings CLI. The command in the terminal is as follows and it works fine in the linux terminal:

`smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'`

When I do run this in the Exec-Node I do get "command failed" due to the time-out that I did set.  
Neither "exec" nor "spawn" options works. The time-out is 120s, which should be long enough.

It must be something about the options. If I do just call the "smartthings" command I do get a reply from the api.

I did copy & paste the command from terminal into the exec-node to be sure there is no typo.  
Maybe something about the characters "/-

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 November 2024 17:02 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/2 "2024-11-13T17:02:45Z")

</div>

Try setting the full path to the command.

If still not working connect the exec node outputs to the debug nodes, configured to Output Full Message and show us what they show.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 November 2024 20:39 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/3 "2024-11-13T20:39:19Z")

</div>

That should have read 'connect the exec node outputs to three debug nodes'.

You can find the full path to the command (smartthings) using the command  
`which smartthings`  
which will say something like  
`/usr/bin/smartthings`  
in which case the command to use in the exec node would be  
`/usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'`

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [14 November 2024 08:41 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/4 "2024-11-14T08:41:54Z")

</div>

Hi @Colin  
thanks for the fast reply.  
Yes, the full path is this:  
`/usr/bin/smartthings`  
And the filling works in my linux terminal:  
`/usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'`

Again, when using the Exec-Node I do rin into a time-out.  
Status of the Exec-Node turns to `killed`

Only two of the three output nodes delivers a feedback (in exec mode):

`{ _msgid: '959eef22fae89b04', topic: '', payload: { code: null, message: Command failed: /usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})', signal: 'SIGTERM' } }`

`{ _msgid: '959eef22fae89b04', topic: '', payload: '', rc: { code: null, message: Command failed: /usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})', signal: 'SIGTERM' } }`

When switching into spawn mode, I do get the same result but only on one other the output nodes.

My timeout setting ist 120 seconds. On the linux terminal I do get a reply from the remote API after max 20 seconds.

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [14 November 2024 08:49 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/5 "2024-11-14T08:49:08Z")

</div>

Interestingly, when I do remove most of the parameters and switch into spawn mode, after sending this:  
`/usr/bin/smartthings devices:commands`

I do get an instant reply from the remote API:  
`{ _msgid: 'd1307f656642a636', payload: 'logging in...', topic: '' }`

Both myDeviceID and myToken are in format: XXXXX-XXXX-XXXXX....

As soon as I do add either the device ID, token or the command it does not work any more.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 November 2024 08:50 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/6 "2024-11-14T08:50:36Z")

</div>

Can you export the exec node and paste it here? Change any sensitive IDs!  
Paste as code using the `</>` button not as a screen capture.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [14 November 2024 08:51 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/7 "2024-11-14T08:51:14Z")

</div>

Send the command via msg.payload

```js
msg.payload = `smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'`

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 November 2024 09:08 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/8 "2024-11-14T09:08:05Z")

</div>

The Smartthings docs seem to say you don't need the = (ie --token XXXX..)  
or maybe use a config file to hold the credentials ?

> **[Get Started With the SmartThings CLI | Developer Documentation | SmartThings](https://developer.smartthings.com/docs/sdks/cli/introduction)**
>
> Find the SmartThings CLI source in our GitHub repo.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [14 November 2024 16:55 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/9 "2024-11-14T16:55:13Z")

</div>

When passing a command including embedded quotes, in here` '..."..."...'` through exec node, I wonder if there is not a problem of quotes on what is executed on the host??

I would try to see effectively what is happening on the host by replacing the command itself `/usr/bin/smartthings` with a shell script that is saving the parameters of the exec command.

Maybe a red herring, though...

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [14 November 2024 18:26 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/10 "2024-11-14T18:26:18Z")

</div>

Thanks. But the issue does not seem to be just the token, but also the other parameters.

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [14 November 2024 18:28 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/11 "2024-11-14T18:28:19Z")

</div>

Of course as a work-around I could pack everything into a bash script and just call the script from with my exe node, but this would take some flexibility in sending different commands, that I would like to create later for more advanced use-cases.

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [14 November 2024 18:35 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/12 "2024-11-14T18:35:05Z")

</div>

Thanks. As suggested did use a "inject node" and did send all parameters as payload. Also I did active the "attach payload" checkbox in the exec-node.

It did not work, same result.

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [14 November 2024 18:38 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/13 "2024-11-14T18:38:58Z")

</div>

@jbudd here is the export

```auto
[
    {
        "id": "28321371bbc38f0c",
        "type": "exec",
        "z": "ba4e13d6eb48084d",
        "command": "/usr/bin/smartthings devices:commands xxxxxx-xxxx-xxxx-xxxx-xxxxxxx --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx 'main:execute:execute(\"/mode/vs/0\",{\"x.com.samsung.da.options\":[\"Sound_Off\"]})'",
        "addpay": "",
        "append": "",
        "useSpawn": "true",
        "timer": "120",
        "winHide": false,
        "oldrc": false,
        "name": "Sound_Off",
        "x": 470,
        "y": 660,
        "wires": [
            [
                "cd1a879fb9ad1bd1"
            ],
            [
                "cd1a879fb9ad1bd1"
            ],
            [
                "cd1a879fb9ad1bd1"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 November 2024 18:50 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/14 "2024-11-14T18:50:03Z")

</div>

> [@PeterSmarthome](#):
>
> Of course as a work-around I could pack everything into a bash script

Try that. It may not work, which will tell us something.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [14 November 2024 19:08 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/15 "2024-11-14T19:08:38Z")

</div>

I am not suggestions to do that forever. I am proposing to look on the host itself (in the Shell) how the full command looks like.  
Simple quote and double quotes, even worse when they are embedded like in your case can give « interesting » results.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 November 2024 23:14 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/16 "2024-11-14T23:14:30Z")

</div>

> [@PeterSmarthome](#):
>
> @jbudd here is the export

I thought that some of the "special" characters might be being mangled , deleted or misinterpreted by the shell. In fact I think your single quotes protect them all from the shell apart from the `=` in `--token=blah`  
What happens if you put the single quotes around everything after smartthings?  
And does this work?

```auto
/usr/bin/smartthings 'devices:commands' 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxx' '--token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx' 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'

```

Just to clarify: when you say it works in the terminal, do you mean that typing that exact command at the dollar prompt works, or is smartthings interactive and you type in response to it's prompt?

What does `file /usr/bin/smartthings` show you?

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [15 November 2024 04:24 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/17 "2024-11-15T04:24:33Z")

</div>

> Just to clarify: when you say it works in the terminal, do you mean that typing that exact command at the dollar prompt works, or is smartthings interactive and you type in response to it's prompt?

I am putting in the command and it will be executed - see screenshot:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/optimized/3X/5/4/54fa88bb3061a4dfbb8bccf5f9875f3524e68eff_2_690x58.png)

The `Command executed successfully` is the reply from the remote API

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [15 November 2024 04:37 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/18 "2024-11-15T04:37:22Z")

</div>

> [@jbudd](#):
>
> What happens if you put the single quotes around everything after smartthings?  
> And does this work?

I tried this:

`/usr/bin/smartthings 'devices:commands d8965e25-caf9-5ef2-41b8-a4f11c87d25d --token=2eec27b1-3c0d-414f-b97c-912b3293e124 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})''`

Doing so results in 2 errors, that appear instantly:

`{"_msgid":"f1418cf01b86ebf7","payload":" › Warning: 'devices:commands is not a smartthings command.\n","topic":""}`

`{"_msgid":"f1418cf01b86ebf7","payload":"Did you mean devices:commands? [y/n]: ","topic":""}`

And 3 further errors after a few seconds:

`{"_msgid":"f1418cf01b86ebf7","payload":"\n","topic":""}`

`{"_msgid":"f1418cf01b86ebf7","payload":" › Error: Run smartthings help for a list of available commands.\n","topic":""}`

`{"_msgid":"f1418cf01b86ebf7","payload":{"code":127},"topic":""}`

I also tried setting the single quotes after devices:command and also around each command. But then I had the same issue as in the beginning -\> running into a time-out after 120 seconds

---

<div class="post-metadata">

**Author:** ![PeterSmarthome](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@PeterSmarthome](https://discourse.nodered.org/u/PeterSmarthome)\
**Post date:** [15 November 2024 05:15 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/19 "2024-11-15T05:15:19Z")

</div>

> [@Colin](#):
>
> Try that. It may not work, which will tell us something.

OK - I made a bash script called "sound\_off.sh":

```auto
#!/bin/bash
/usr/bin/smartthings devices:commands xxxxxx-xxxx-xxxx-xxxx-xxxxxxx --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'

```

Calling it on command line in the linux terminal works fine:

```auto
$ /usr/sbin/sound_off.sh
Command executed successfully

```

I did put the command `/usr/sbin/sound_off.sh` into my exec-node and interestingly getting this result after waiting 120 seconds (the timeout that I did set):

First a succes message and then a time-out error:  
`{"_msgid":"442ed2ec574d589e","topic":"","payload":"Command executed successfully\n","rc":{"code":null,"message":"Command failed: /usr/sbin/sound_off.sh\n","signal":"SIGTERM"}}`

Same result in "exec" and "spawn" mode (in spawn mode the above message will be split into two messages)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [15 November 2024 05:30 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/20 "2024-11-15T05:30:40Z")

</div>

And did it actually turn off the sound ?  
Then it might be a matter of the way the script exits (or the smartthings command for that matter).

[Next page](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126.md?page=2)
