# Using 'exec' node without sudo

**URL:** https://discourse.nodered.org/t/using-exec-node-without-sudo/42595
**Category:** General
**Created:** [13 March 2021 20:10 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595 "2021-03-13T20:10:45Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [13 March 2021 20:10 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/1 "2021-03-13T20:10:45Z")

</div>

Hi everyone,

I am trying to use playerctl through the exec node, but the commands are returning an error:

`Command failed: playerctl pause Could not connect to players: Cannot autolaunch D-Bus without X11 $DISPLAY`

I suspect the exec node is running all commands with sudo as this error only appears in the terminal when I attempt to run it with sudo.

Is there a way to run commands on the exec node without sudo? e.g. just as my user profile?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [13 March 2021 20:13 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/2 "2021-03-13T20:13:19Z")

</div>

> [@WhatDoor](#):
>
> I suspect the exec node is running all commands with sudo

Are you running node-red as sudo?

Are you running node-red under docker? or snap?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [13 March 2021 20:18 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/3 "2021-03-13T20:18:35Z")

</div>

Try starting your command with `DISPLAY=:0 `

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [13 March 2021 20:25 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/4 "2021-03-13T20:25:32Z")

</div>

I tried 'DISPLAY=:0 playerctl pause' and got

`Error spawning command line âdbus-launch --autolaunch=4a6306b2731d448daedf11f8f399f8de --binary-syntax --close-stderrâ: Child process exited with code 1`

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [13 March 2021 20:26 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/5 "2021-03-13T20:26:05Z")

</div>

node-red likely to be running in sudo, but I'm not sure how to check

---

<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 March 2021 20:54 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/6 "2021-03-13T20:54:08Z")

</div>

I don't think that is the case, unless you installed node-red in an unusual way. What OS are you running on and how did you install node-red?

What folder is the flows file in? It tells you that when you start node-red.

Add debug to all three outputs of the exec node, set them to show Complete Message and see if you get any more information.

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [13 March 2021 21:04 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/7 "2021-03-13T21:04:34Z")

</div>

Been a while since i installed node red, but I'm pretty sure I just followed this tutorial -

[https://nodered.org/docs/getting-started/raspberrypi](https://nodered.org/docs/getting-started/raspberrypi)

This is my OS:  
PRETTY\_NAME="Raspbian GNU/Linux 10 (buster)"  
NAME="Raspbian GNU/Linux"  
VERSION\_ID="10"  
VERSION="10 (buster)"  
VERSION\_CODENAME=buster  
ID=raspbian  
ID\_LIKE=debian

It's possible I've misdiagnosed the issue...?

---

<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 March 2021 21:09 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/8 "2021-03-13T21:09:10Z")

</div>

So what is the folder and do you see anything helpful in the debug nodes that I suggested?

> [@WhatDoor](#):
>
> It's possible I've misdiagnosed the issue...?

I think so.

Also can you show us how you have configured the exec node?

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [13 March 2021 21:25 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/9 "2021-03-13T21:25:12Z")

</div>

The flows are stored in - /home/pi/.node-red/flows\_raspberrypi.json

The error messages that I have been posting so far come from the debug node, no further details given:

```auto
Command failed: playerctl pause Could not connect to players: Cannot autolaunch D-Bus without X11 $DISPLAY
Error spawning command line âdbus-launch --autolaunch=4a6306b2731d448daedf11f8f399f8de --binary-syntax --close-stderrâ: Child process exited with code 1

```

And the exec node is configured like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/b/cba5856b1519f6e6fac003ee879fed39d4c979b2.png)

---

<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 March 2021 21:51 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/10 "2021-03-13T21:51:56Z")

</div>

As you are running node-red as the user `pi` then it won't be running as root.

You haven't got the DISLAY=:0 setting. You need that. That is why it is saying that it cannot autolaunch without a configured display.

Has your Pi got a display fitted and is it the full raspbian that you installed and is the GUI enabled?

If you connect to the pi via an ssh shell and run the command does it work? You will need the DISPLAY set there too.

> [@WhatDoor](#):
>
> The error messages that I have been posting so far come from the debug node, no further details given:

Have you got the debug nodes on all three outputs and are they configured to show Complete Message?

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [13 March 2021 22:46 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/11 "2021-03-13T22:46:31Z")

</div>

I could connect the RPI to a monitor but I have been using it headlessly for a awhile now.

The weird part is that the commands (without DISPLAY) work find in an SSH terminal, but the same commands don't work in exec.

But when I run the commands in SSH with sudo, I get the same output as what I see in node red. Which is why I thought that was the issue.

I'll look into getting the complete log

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [14 March 2021 06:59 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/12 "2021-03-14T06:59:22Z")

</div>

I've attached all three outputs to an output node, and it just produces

```auto
{"code":1,"message":"Command failed: DISPLAY=:0 playerctl -l\nError spawning command line âdbus-launch --autolaunch=4a6306b2731d448daedf11f8f399f8de --binary-syntax --close-stderrâ: Child process exited with code 1\n"}

```

when I do DISPLAY=:0 playerctl -l. I'm not sure what you mean by 'configured to show Complete Message'? Where is that setting?

DISPLAY=:0 playerctl -l does work in my ssh terminal though.

---

<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 March 2021 07:31 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/13 "2021-03-14T07:31:03Z")

</div>

> [@WhatDoor](#):
>
> 'configured to show Complete Message'? Where is that setting?

In the drop-down in the debug node.

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [14 March 2021 07:54 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/14 "2021-03-14T07:54:59Z")

</div>

Here are the three outputs of the complete message, looks like it is the same thing?

```auto
{"_msgid":"6a838666.05aa58","topic":"","payload":"","rc":{"code":1,"message":"Command failed: DISPLAY=:0 playerctl -l\nError spawning command line âdbus-launch --autolaunch=4a6306b2731d448daedf11f8f399f8de --binary-syntax --close-stderrâ: Child process exited with code 1\n"}}

```

```auto
{"_msgid":"6a838666.05aa58","topic":"","payload":"Error spawning command line âdbus-launch --autolaunch=4a6306b2731d448daedf11f8f399f8de --binary-syntax --close-stderrâ: Child process exited with code 1\n","rc":{"code":1,"message":"Command failed: DISPLAY=:0 playerctl -l\nError spawning command line âdbus-launch --autolaunch=4a6306b2731d448daedf11f8f399f8de --binary-syntax --close-stderrâ: Child process exited with code 1\n"}}

```

```auto
{"_msgid":"6a838666.05aa58","topic":"","payload":"Error spawning command line âdbus-launch --autolaunch=4a6306b2731d448daedf11f8f399f8de --binary-syntax --close-stderrâ: Child process exited with code 1\n","rc":{"code":1,"message":"Command failed: DISPLAY=:0 playerctl -l\nError spawning command line âdbus-launch --autolaunch=4a6306b2731d448daedf11f8f399f8de --binary-syntax --close-stderrâ: Child process exited with code 1\n"}}

```

---

<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 March 2021 08:45 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/15 "2021-03-14T08:45:23Z")

</div>

OK, it was worth doing in case there was more information.  
Try the exec node in Spawn mode instead of Complete mode.

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [14 March 2021 08:53 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/16 "2021-03-14T08:53:55Z")

</div>

Okay, so in Spawn mode.

playerctl -l:

```auto
{"_msgid":"dd257073.0682e","payload":"Cannot autolaunch D-Bus without X11 $DISPLAY\n","topic":""}

```

```auto
{"_msgid":"dd257073.0682e","payload":{"code":1},"topic":""}

```

DISPLAY=:0 playerctl -l

```auto
{"_msgid":"7f3fd4d8.02e0cc","payload":{"code":-2},"topic":""}

```

---

<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 March 2021 09:16 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/17 "2021-03-14T09:16:08Z")

</div>

You have lost the DISPLAY setting again. Note that is the same error that you got without that earlier, saying that it cannot even try to launch dbus. The error when you do specify the display is that it doesn't start properly, but is at least able to try, so it does get further.

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [14 March 2021 09:23 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/18 "2021-03-14T09:23:31Z")

</div>

I'm not sure if I follow... and I'm stumped as to what I can try next.

Can you please elaborate further?

---

<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 March 2021 10:12 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/19 "2021-03-14T10:12:57Z")

</div>

Sorry, I didn't read your reply properly, I see you have tried it with and without.  
Well that is progress I think.  
With the DISPLAY setting, which output is the message coming from?

Try putting the full path to the playerctl command. Run `which playerctl` to find that.

---

<div class="post-metadata">

### Author: ![WhatDoor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whatdoor/32/38762_2.png) [@WhatDoor](https://discourse.nodered.org/u/WhatDoor)
#### Post date: [14 March 2021 20:08 UTC](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595/20 "2021-03-14T20:08:18Z")

</div>

The message is coming from the return code output.

Running `DISPLAY:=0 /usr/bin/playerctl -l` returns the same thing

[Next page](https://discourse.nodered.org/t/using-exec-node-without-sudo/42595.md?page=2)
