# Program can't connect to X server when started by node-red

**URL:** <https://discourse.nodered.org/t/program-cant-connect-to-x-server-when-started-by-node-red/6519>\
**Category:** General\
**Created:** [7 January 2019 16:24 UTC](https://discourse.nodered.org/t/program-cant-connect-to-x-server-when-started-by-node-red/6519 "2019-01-07T16:24:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [7 January 2019 16:24 UTC](https://discourse.nodered.org/t/program-cant-connect-to-x-server-when-started-by-node-red/6519/1 "2019-01-07T16:24:36Z")

</div>

I stumped here, I've a shell script that starts my pythonAI. It works fine on Raspberry Pi Stretch when launched by a node-red exec node. But when launhed on Ubuntu 18.04 node red it dies with ": cannot connect to X server" in my log file. If I run the script from a terminal on the Ubuntu machine it works as expected. If I launch it from my desktop (where the node-red webpage is being viewed/edited) via ssh -X it works. I get the X display locally when launched from the 18.04 terminal and I get the the X display on my desktop when launched with ssh -X.

Why does running the script via node-red exec node not work the same as launching it via a terminal login?

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [7 January 2019 16:29 UTC](https://discourse.nodered.org/t/program-cant-connect-to-x-server-when-started-by-node-red/6519/2 "2019-01-07T16:29:33Z")

</div>

Does this script run a GUI application? If so, I'd suspect that running it from a background server does not have a Display to work with. If that's missing, you may be able to add a line to the script that sets the env variable for specifying which display to use...

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [7 January 2019 16:49 UTC](https://discourse.nodered.org/t/program-cant-connect-to-x-server-when-started-by-node-red/6519/3 "2019-01-07T16:49:24Z")

</div>

How exactly do you launch the script, what commands?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [7 January 2019 18:18 UTC](https://discourse.nodered.org/t/program-cant-connect-to-x-server-when-started-by-node-red/6519/4 "2019-01-07T18:18:31Z")

</div>

Hi,  
Not Ubuntu but I have Debian installed on a laptop and NR launches a Python script and it works fine. I use this command in the exec node:

> export DISPLAY=:0 && uxterm -geometry 96x24-400+200 -e /usr/bin/python /home/pi/dnn\_pq\_analyzer.py

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/ad2068658a3ce34a9748e29520d1c13c6c43980e.png)

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [7 January 2019 21:37 UTC](https://discourse.nodered.org/t/program-cant-connect-to-x-server-when-started-by-node-red/6519/5 "2019-01-07T21:37:07Z")

</div>

Basically my script only uses the X display when running in a debug/setup mode, I'd forgotten that I'd changed the default to be that mode while making a "unified" version that runs on Windows and Linux. For my purposes it doesn't really make sense to start in the debug/setup mode from node-red since it is ultimately intended to run "headless", so I changed my start up script to invoke it with my parameter to suppress the display. This should prevent re-occurrence on other systems irrespective if I forget to reset the default or not.

krambriw's solution will be filed away should I ever have the need to start an X app from node-red, although actually all I needed to do was add:

> export DISPLAY=:0

To my script before executing the command and then the debug/setup windows do popup when started from node-red.

Thanks!
