# Exec script to UI app

**URL:** <https://discourse.nodered.org/t/exec-script-to-ui-app/14643>\
**Category:** General\
**Created:** [22 August 2019 11:54 UTC](https://discourse.nodered.org/t/exec-script-to-ui-app/14643 "2019-08-22T11:54:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicorl](https://avatars.discourse-cdn.com/v4/letter/n/4af34b/32.png) [@nicorl](https://discourse.nodered.org/u/nicorl)\
**Post date:** [22 August 2019 11:54 UTC](https://discourse.nodered.org/t/exec-script-to-ui-app/14643/1 "2019-08-22T11:54:12Z")

</div>

Hi,  
First of all, thanks everyone to take your time to help. English is not my mature language and I apologize beforehand for that.

I have a node with exec easy sentence: script.md

The code in script.md is:  
lxterminal python3 my\_script.py

It wouldn't be a problem unless I'm working with opencv dependencies, and I have to see the camera output on the monitor.  
If I run the script from terminal, it just works. But through the node-red, I always have the same issue:  
(lxterminal:1604): Gtk-WARNING \*\*: cannot open display:

lxterminal is because i'm working in a raspberry pi.

PD: I use node-red because I want to run this script when the device receive a message in a broker/topic. If you have any other suggestion to do that I'll be grateful to learn 🙂

Thanks

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [23 August 2019 21:00 UTC](https://discourse.nodered.org/t/exec-script-to-ui-app/14643/2 "2019-08-23T21:00:52Z")

</div>

You are running a script using the GTK toolkit that requires access to a desktop GUI. In fact, you are using the LXDE's desktop terminal app to run a PYTHON programme and you don't need to do that.

Your script should simply be `python3 my_script.py`. And for that, you can simply add that command to a Node-RED `exec` node. The output of the script will be returned as a msg to Node-RED and you can output it or process it as needed.

---

<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:** [24 August 2019 05:46 UTC](https://discourse.nodered.org/t/exec-script-to-ui-app/14643/3 "2019-08-24T05:46:20Z")

</div>

And just to add, if you really want to show the script running on the monitor, you can use a command like this in the exec node:

```auto
export DISPLAY=:0 && lxterminal -e python3 /home/pi/my_script.py

```

---

<div class="post-metadata">

**Author:** ![nicorl](https://avatars.discourse-cdn.com/v4/letter/n/4af34b/32.png) [@nicorl](https://discourse.nodered.org/u/nicorl)\
**Post date:** [24 August 2019 10:42 UTC](https://discourse.nodered.org/t/exec-script-to-ui-app/14643/4 "2019-08-24T10:42:09Z")

</div>

Thanks both for answer. I'll try on monday.

My best try to get my goal was adding a "watchdog" python script in crontab and use it for lauch my `python3 my_script`.  
It worked but isn't a good way to solve.

Thanks again you for your time and consideration.  
🙂

---

<div class="post-metadata">

**Author:** ![votecoffee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/votecoffee/32/31932_2.png) [@votecoffee](https://discourse.nodered.org/u/votecoffee)\
**Post date:** [18 January 2021 18:26 UTC](https://discourse.nodered.org/t/exec-script-to-ui-app/14643/5 "2021-01-18T18:26:17Z")

</div>

I'm trying to run a python script using an IntelD435, and I get the same error. I'm running using a daemon node however. I installed lxterminal. The command shows as not found. Any thoughts on how to implement for daemon node?

---

<div class="post-metadata">

**Author:** ![votecoffee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/votecoffee/32/31932_2.png) [@votecoffee](https://discourse.nodered.org/u/votecoffee)\
**Post date:** [18 January 2021 19:19 UTC](https://discourse.nodered.org/t/exec-script-to-ui-app/14643/6 "2021-01-18T19:19:17Z")

</div>

I figured out you can set the environment variables within the python script:

```auto
os.environ["DISPLAY"] = ':0'
os.environ["XAUTHORITY"] = '/home/user/.Xauthority'

```
