# 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:** 2

<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:46 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/21 "2024-11-15T05:46:19Z")

</div>

yes, it turns the sound off. But only after the node-execution is being terminated by the time-out and the node turns into status "killed"

---

<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 07:27 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/22 "2024-11-15T07:27:56Z")

</div>

Can you try to add

```auto
exit 0 

```

in the script ?  
and you could try to add `>/dev/null2>&1` to the end of your command as well to ignore the output and then exit.

---

<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:** [15 November 2024 07:52 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/23 "2024-11-15T07:52:23Z")

</div>

If your script works from the command line but not from Node-red it could be an environment difference, especially if smartthings is also a shell script. That's why I asked what `file /usr/bin/smartthings` shows you.

Smartthings might behave differently if it is called from an interactive shell ie the command line, or a non-interactive one but I'd expect using your script to reveal that.

---

<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:** [15 November 2024 08:19 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/24 "2024-11-15T08:19:26Z")

</div>

I am on my phone and can't immediately see whether you have told us what versions of node red and nodejs you are using.

---

<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 08:50 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/25 "2024-11-15T08:50:17Z")

</div>

Also interesting to compare the outcome in the linux terminal and the exec node (spawn-mode) calling these following commands:

First, just `/usr/bin/smartthings devices:commands` without any further options:

Linux Terminal is turning into "login-mode" , waiting endlessly (can not do anything until CRTL-C, neither entering token, nor deviceID helps)

```auto
/usr/bin/smartthings devices:commands
logging in... ⣷

```

Using same command in the exec-node returns immediatly:  
`{"_msgid":"39f4c3aad4b441f2","payload":"logging in...","topic":""}`  
After the time-out the node turns to status "killed"

**So far both ways work in a consistent way.**

Now I do also add just the token, nothing else and do call this on both terminal and exec-node:  
`/usr/bin/smartthings devices:commands --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx`

The terminal looks like this:

```auto
$ /usr/bin/smartthings devices:commands --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx
──────────────────────────────────────────────────────────────────────
 # Label Name Type Device Id                            
──────────────────────────────────────────────────────────────────────
 1 Herd [oven] Samsung OCF xxxxxx-xxxx-xxxx-xxxx-xxxxxxx 
──────────────────────────────────────────────────────────────────────
? Select a device.

```

The output of the exec-node is this:  
`{"_msgid":"1958eb1335e84903","payload":"──────────────────────────────────────────────────────────────────────\n # Label Name Type Device Id \n──────────────────────────────────────────────────────────────────────\n 1 Herd [oven] Samsung OCF xxxxxx-xxxx-xxxx-xxxx-xxxxxxx \n──────────────────────────────────────────────────────────────────────\n","topic":""}`

`{"_msgid":"1958eb1335e84903","payload":"? Select a device. ","topic":""}`

`{"_msgid":"1958eb1335e84903","payload":[27,91,49,57,68,27,91,49,57,67],"topic":""}`

And when time-out is reached:  
`{"_msgid":"1958eb1335e84903","payload":{"code":null,"signal":"SIGTERM"},"topic":""}`

**So again, the result is more or less consitent on both terminal and exec-node.**

But now the interesting part: I use both deviceID and Token (nothing else, so far):  
`/usr/bin/smartthings devices:commands xxxxxx-xxxx-xxxx-xxxx-xxxxxxx --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx`

```auto
$ /usr/bin/smartthings devices:commands xxxxxx-xxxx-xxxx-xxxx-xxxxxxx --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx

Herd

Components:
──────────────
 1 main      
 2 cavity-01 
──────────────

```

The terminal goes into some interactive mode where I can chose some options.

On the exec-node this happens:  
`{"_msgid":"92d7fa0a8230efa1","payload":{"code":null,"signal":"SIGTERM"},"topic":""}`

**So, when adding the deviceID, the linux terminal and the exec-node do no longer appear to work in a constant way** The reply from the API is not available on the exec-node, which is exactly the issue I have been running into at the start.

Please note:  
The smartthings script enters some kind of interactive mode, when parameters are missing.  
The smatterings script executes the command and exits on the terminal when all parameters are set correctly.

---

<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 08:54 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/26 "2024-11-15T08:54:17Z")

</div>

Node-Red: 5.2.1  
JS-Controller: 6.0.11

---

<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:** [15 November 2024 09:23 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/27 "2024-11-15T09:23:53Z")

</div>

> [@PeterSmarthome](#):
>
> Node-Red: 5.2.1

Node red current version is 4.0.5. It is shown at the bottom of the Dropdown menu in the editor.  
How did you install node-red?

For the nodejs version use `node -v`

---

<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:** [15 November 2024 10:02 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/28 "2024-11-15T10:02:33Z")

</div>

> [@PeterSmarthome](#):
>
> The terminal goes into some interactive mode where I can chose some options.

If you can work out the sequence of commands needed when smartthings is in interactive mode, you may be able to fudge the exec node using a template node like below and exec with no command but "append msg.payload" ticked.

```auto
/usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> << !
(Your sequence of commands to control smartthings, 1 command per line)
(include "quit", "exit" or whatever works for smartthings)
!

```

The `<< !` and final `!` is "inline redirection of stdin" and it's not pretty but it might just work!

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 November 2024 10:20 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/29 "2024-11-15T10:20:27Z")

</div>

(just passing bye)

Um, so if you can run a `bash script` and it turns the sound off....

edit that script to accept options.... (or sorry: one)  
That being to turn the sound either off or on.

`#!/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"]})'`

So something like:

`#!/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":' $1`

and run it with (sorry scripting is not my best)  
`Sound_Off` or `Sound_On` as parameters.

See if you can get it working that way.  
Yes, I know those examples are NOT the exact things needed. Only to show what I mean.

If you get it working that way, MAYBE you could expand on it that way.

🤷

Just a thought.

---

<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 19:38 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/30 "2024-11-15T19:38:37Z")

</div>

Frist of all, thank you very much for the many feedbacks. I just did register two day before to post my issue here and I did get so much support!!! Thanks.

Because I am a new user here, I am restricted in the number of post, and sometimes I have to wait for hours before I can post a reply. Therfore I am packing all replies into this post.

> [@jbudd](#):
>
> If your script works from the command line but not from Node-red it could be an environment difference, especially if smartthings is also a shell script. That's why I asked what `file /usr/bin/smartthings` shows you.

```auto
$ file /usr/bin/smartthings
/usr/bin/smartthings: symbolic link to ../lib/node_modules/@smartthings/cli/bin/run

```

/////////////////////////////////////////////

> [@Colin](#):
>
> Node red current version is 4.0.5. It is shown at the bottom of the Dropdown menu in the editor.  
> How did you install node-red?

Node-Red: v3.1.9  
node JS v18.20.4

/////////////////////////////////////////////

> [@jbudd](#):
>
> That's why I asked what `file /usr/bin/smartthings` shows you.

```auto
$ file /usr/bin/smartthings
/usr/bin/smartthings: symbolic link to ../lib/node_modules/@smartthings/cli/bin/run

```

/////////////////////////////////////////////

> [@bakman2](#):
>
> and you could try to add `>/dev/null2>&1` to the end of your command as well to ignore the output and then exit.

with the `>/dev/null2>&1` I do get a "permission denied"

/////////////////////////////////////////////

> [@Trying\_to\_learn](#):
>
> Um, so if you can run a `bash script` and it turns the sound off....
> 
> edit that script to accept options.... (or sorry: one)  
> That being to turn the sound either off or on.

Yes, did this and it works. I wrote a script `/usr/sbin/samsung_setSound.sh`:

```auto
#!/bin/bash
/usr/bin/smartthings devices:commands $1 --token=$2 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["'$3'"]})'
exit 0

```

Then I do call it from the exec-node like this:  
`/usr/sbin/samsung_setSound.sh xxxxxx-xxxx-xxxx-xxxx-xxxxxxx xxxxxx-xxxx-xxxx-xxxx-xxxxxxx "Sound_Off"`

As soon as the exec-node runs into the time-out, that I did set to as short 1s I get the results:  
`{"_msgid":"db9216da39f278ce","payload":"Command executed successfully\n","topic":""}`

`{"_msgid":"db9216da39f278ce","payload":{"code":null,"signal":"SIGTERM"},"topic":""}`

Still not perfect because of the time-out, but at least I get what I was looking for.

---

<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:** [15 November 2024 21:19 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/31 "2024-11-15T21:19:08Z")

</div>

> [@PeterSmarthome](#):
>
> Because I am a new user here, I am restricted in the number of post,

I have boosted your trust level, so that should be improved.

I think it must be something unusual about the way the smartthings command is spawning sub-processes to do the work, which is confusing the exec node. If you run the command directly from the command line then after it returns to the prompt what does this command show?  
`ps aux|grep smartthings`

I don't know whether there were any improvements in that area but it would be worth upgrading to the latest node-red, if you can, just in case the situation has improved.

You didn't answer the question - How did you install node-red?

---

<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:** [15 November 2024 22:27 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/32 "2024-11-15T22:27:32Z")

</div>

Did you try my inline redirection suggestion?

---

<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 23:51 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/33 "2024-11-15T23:51:48Z")

</div>

> [@Colin](#):
>
> If you run the command directly from the command line then after it returns to the prompt what does this command show?  
> `ps aux|grep smartthings`

This is how it looks like:

```auto
$ /usr/bin/smartthings devices:commands <deviceID> token=<authToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'
Command executed successfully

$ ps aux|grep smart things
peter 5516 0.0 0.0 6612 2304 pts/0 S+ 00:47 0:00 grep --color=auto **smartthings**

```

---

<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 23:55 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/34 "2024-11-15T23:55:49Z")

</div>

> [@Colin](#):
>
> You didn't answer the question - How did you install node-red?

It came with my ioBroker. There is an official so-called "adapter" for node-red. v3.1.9 is the latest available version of the adapter. I need to find out how to upgrade without breaking my ioBroker system.

---

<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:** [16 November 2024 00:19 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/35 "2024-11-16T00:19:30Z")

</div>

> [@jbudd](#):
>
> Did you try my inline redirection suggestion?

In the interactive mode it goes like this:

```auto
$ /usr/bin/smartthings devices:commands <deviceID> --token=<authToken>

Herd

Components:
──────────────
 1 main      
 2 cavity-01 
──────────────

? Enter component index or id: main

Capabilities:
───────────────────────────────────────────
 1 ocf                                   
 2 execute                               
 3 refresh                               
 4 remoteControlStatus                   
 ...    
 24 custom.disabledCapabilities           
───────────────────────────────────────────

? Enter capability index or id: execute

Commands:
─────────────────────────────────────────────────
 1 execute(command<string>, [args<JsonObject>]) 
─────────────────────────────────────────────────

? Enter command: execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})
Command executed successfully

$ 

```

So, I changed my script like this:

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

```

Result in linux terminal is: `Error: got simple string from stdin`

---

<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:** [16 November 2024 00:51 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/36 "2024-11-16T00:51:48Z")

</div>

OK well

```auto
main
execute
...

```

is what I had in mind, so I assume that you have used the right syntax for the actual command, even though it looks like several commands combined as one.

And that's not exactly a simple string, so I wonder if it's the `!` that triggers the error.

Is there a quit command for the CLI, besides CTRL - C, that you can include before the `!` ?

Maybe I have you chasing red herrings and it's not worth pursuing this approach any more.

---

<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:** [16 November 2024 05:53 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/37 "2024-11-16T05:53:46Z")

</div>

Where did you actually find the command format you are using ?  
Looking at the [(extensive) documentation](https://github.com/SmartThingsCommunity/smartthings-cli?tab=readme-ov-file#smartthings-devicescommands-id-command), it should be something like:

```auto
smartthings devices:commands <device-id> 'switchLevel:setLevel(50)'

```

---

<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:** [16 November 2024 08:17 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/38 "2024-11-16T08:17:51Z")

</div>

> [@jbudd](#):
>
> Is there a quit command for the CLI, besides CTRL - C, that you can include before the `!` ?

No, the smartthings just exits automatically, either once a command is sent or the user inputs anything "invalid"

---

<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:** [16 November 2024 08:36 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/39 "2024-11-16T08:36:15Z")

</div>

> [@bakman2](#):
>
> Where did you actually find the command format you are using ?  
> Looking at the [(extensive) documentation](https://github.com/SmartThingsCommunity/smartthings-cli?tab=readme-ov-file#smartthings-devicescommands-id-command), it should be something like:
> 
> ```auto
> smartthings devices:commands <device-id> 'switchLevel:setLevel(50)'
> 
> ```

The SmartThings API works in a very generic way because it supports wide range of devices. There are many functions you could not call just like you described it above. In many cases you have to call an "execute" command and provide somethings that looks like a CLI that will be forwarded to the device. Sometimes the commands are not officially documented and people are "sniffing" their Samsung APPs to find out, what is going on.

I did find the commands for the sound setting here: [LINK](https://community.smartthings.com/t/samsung-oven-range-and-cooktop-sync-time-api/251391/7?u=petersmarthome)

Also in alternative to using the smartthings CLI script, you could call the RestAPIs directly using a http-request node, but when I started I thought it would be more convenient to use an official script, that handles all the communication and I "just" need to call the command...

---

<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:** [16 November 2024 08:59 UTC](https://discourse.nodered.org/t/exec-node-works-fine-in-linux-terminal-but-not-in-exec-node/93126/40 "2024-11-16T08:59:17Z")

</div>

Ok,

could you try your script using this:

```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"]})' & PID=$!; sleep 3; kill -s SIGINT $PID

```

it will capture its PID and kills it after 3 seconds. Run it in exec mode.

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

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