# Command works in terminal but not in exec node

**URL:** <https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087>\
**Category:** General\
**Created:** [12 December 2021 17:08 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087 "2021-12-12T17:08:44Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [12 December 2021 17:08 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/1 "2021-12-12T17:08:45Z")

</div>

The following command works fine in the console, but not in the exec node in Buster, but used to work in Stretch.

ffplay Desktop/audio.mp3 \>/dev/null 2\>&1 -vn -autoexit -nodisp

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/953f502ec27eed77d6daa08a322eacf7473b5c48.png)

```auto
[{"id":"866572cd.1cabb","type":"comment","z":"0f9a9065356bf9a1","name":"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello+World","info":"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello+World","x":380,"y":60,"wires":[]},{"id":"b1e32597.2c78a8","type":"inject","z":"0f9a9065356bf9a1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Goodbye","payloadType":"str","x":80,"y":180,"wires":[["597a0b09.032f54"]]},{"id":"67bd15e7.7e05cc","type":"inject","z":"0f9a9065356bf9a1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello","payloadType":"str","x":90,"y":120,"wires":[["597a0b09.032f54"]]},{"id":"bae924d9.b41608","type":"play audio","z":"0f9a9065356bf9a1","name":"","voice":"0","x":750,"y":180,"wires":[]},{"id":"597a0b09.032f54","type":"function","z":"0f9a9065356bf9a1","name":"TTS","func":"msg.url =\"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=\"+msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":140,"wires":[["1a67f7f4.ceebf8"]]},{"id":"1a67f7f4.ceebf8","type":"http request","z":"0f9a9065356bf9a1","name":"Download mp3","method":"GET","ret":"bin","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":460,"y":140,"wires":[["fb043dc9.03987"]]},{"id":"5aa18234.1e1cfc","type":"exec","z":"0f9a9065356bf9a1","command":"ffplay Desktop/audio.mp3","addpay":"","append":">/dev/null 2>&1 -vn -autoexit -nodisp","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":790,"y":240,"wires":[[],[],[]]},{"id":"fb043dc9.03987","type":"file","z":"0f9a9065356bf9a1","name":"File write to Buffer","filename":"/home/pi/Desktop/audio.mp3","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":470,"y":180,"wires":[["5aa18234.1e1cfc","bae924d9.b41608"]]},{"id":"819b3cfeb9606e49","type":"comment","z":"0f9a9065356bf9a1","name":"Output on Browser","info":"","x":770,"y":140,"wires":[]},{"id":"bc3fe0386551d616","type":"comment","z":"0f9a9065356bf9a1","name":"Output to Bluetooth Speaker","info":"","x":800,"y":300,"wires":[]},{"id":"a1f9ee40e25fa20d","type":"comment","z":"0f9a9065356bf9a1","name":"ffplay Desktop/audio.mp3 >/dev/null 2>&1 -vn -autoexit -nodisp","info":"So by specifying > /dev/null 2>&1 you tell the system that you want to redirect the command's standard output into /dev/null, then redirect standard error into standard output (which in turn is redirected into /dev/null). This has the effect of silencing the command by throwing away all of its output that is sent to either stdout or stderr.","x":680,"y":340,"wires":[]}]

```

Is there an issue with Node Red Exec Node in Buster?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [12 December 2021 17:52 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/2 "2021-12-12T17:52:59Z")

</div>

There's no known issue with the exec node.

I just tried your flow out on my Pi4 Buster and it worked without error (except I don't have a bluetooth speaker connected so I don't know if that bit would actually make a sound)

maybe add full path to the audio.mp3 file? /home/Pi/Desktop/audio.mp3

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [12 December 2021 18:20 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/3 "2021-12-12T18:20:23Z")

</div>

Thanks, so does the ffplay work through the command node on your system and output to a wire connected speaker to your Pi4?  
The ffplay in the terminal outputs to my bluetooth speaker without issues, but does not output from the exec node.  
Changing the output to the full path had no effect.

Or is there an issue with the exec node in Node Red Version 2?

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [12 December 2021 23:05 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/4 "2021-12-12T23:05:42Z")

</div>

Resolved

Prefixing the ffplay in the exec node with the following appears to resolve the issue.

> DISPLAY=:0

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75e45c8f92d1465c1c7dca31eb614af8493839f3.png)

```auto
[{"id":"0f9a9065356bf9a1","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"866572cd.1cabb","type":"comment","z":"0f9a9065356bf9a1","name":"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello+World","info":"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello+World","x":380,"y":60,"wires":[]},{"id":"b1e32597.2c78a8","type":"inject","z":"0f9a9065356bf9a1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Goodbye","payloadType":"str","x":80,"y":180,"wires":[["597a0b09.032f54"]]},{"id":"67bd15e7.7e05cc","type":"inject","z":"0f9a9065356bf9a1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello","payloadType":"str","x":90,"y":120,"wires":[["597a0b09.032f54"]]},{"id":"bae924d9.b41608","type":"play audio","z":"0f9a9065356bf9a1","name":"","voice":"0","x":750,"y":180,"wires":[]},{"id":"597a0b09.032f54","type":"function","z":"0f9a9065356bf9a1","name":"TTS","func":"msg.url =\"https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=\"+msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":140,"wires":[["1a67f7f4.ceebf8"]]},{"id":"1a67f7f4.ceebf8","type":"http request","z":"0f9a9065356bf9a1","name":"Download mp3","method":"GET","ret":"bin","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":460,"y":140,"wires":[["fb043dc9.03987"]]},{"id":"5aa18234.1e1cfc","type":"exec","z":"0f9a9065356bf9a1","command":"DISPLAY=:0 ffplay Desktop/audio.mp3 ","addpay":"","append":">/dev/null 2>&1 -vn -autoexit -nodisp","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":830,"y":240,"wires":[[],[],[]]},{"id":"fb043dc9.03987","type":"file","z":"0f9a9065356bf9a1","name":"File write to Buffer","filename":"/home/pi/Desktop/audio.mp3","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":470,"y":180,"wires":[["5aa18234.1e1cfc","bae924d9.b41608"]]},{"id":"819b3cfeb9606e49","type":"comment","z":"0f9a9065356bf9a1","name":"Output on Browser","info":"","x":770,"y":140,"wires":[]},{"id":"bc3fe0386551d616","type":"comment","z":"0f9a9065356bf9a1","name":"Output to Bluetooth Speaker","info":"","x":800,"y":300,"wires":[]},{"id":"a1f9ee40e25fa20d","type":"comment","z":"0f9a9065356bf9a1","name":"ffplay Desktop/audio.mp3 >/dev/null 2>&1 -vn -autoexit -nodisp","info":"So by specifying > /dev/null 2>&1 you tell the system that you want to redirect the command's standard output into /dev/null, then redirect standard error into standard output (which in turn is redirected into /dev/null). This has the effect of silencing the command by throwing away all of its output that is sent to either stdout or stderr.","x":680,"y":340,"wires":[]}]

```

Why this should be necessary now, but wasn't in previous versions of Raspbian/Node Red I have no idea. Any explanation appreciated.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 December 2021 10:49 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/5 "2021-12-13T10:49:50Z")

</div>

In the `exec` node, I notice you are not providing the full path to the audio file. Try adding the full path and see if you can remove the `DISPLAY=:0`

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [13 December 2021 12:33 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/6 "2021-12-13T12:33:37Z")

</div>

As I said above, already tried, and changing the output in the exec node to the full path had no effect. Only seems to work if DISPLAY=:0 is added.

Incidentally the purpose of the code is usually for communicating with an Amazon Alexa Dot speaker, but is also being tested here using bluetooth earphones.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 December 2021 13:20 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/7 "2021-12-13T13:20:08Z")

</div>

I don't have a bluetooth speaker, but I just ran it without the 'DISPLAY=:0" on a Pi3 (Buster lite) with the full path to the file and I hear sound from the audio jack (earphones plugged in)

Have you added debug nodes (set to display the complete msg object) to the three outputs of the `exec` node to see if they show anything?

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [13 December 2021 14:23 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/8 "2021-12-13T14:23:11Z")

</div>

There is only output from Stdout and the Return Code, nothing from Stderr. Hope the following output gives you some insight. Incidentally when it works over bluetooth by including the DISPLAY=:0, there is a considerable 5 sec delay before output of sound.

13/12/2021, 14:08:37node: 0873e50e140abde5  
msg : Object  
object  
_msgid: "3763f73409a045f9"  
topic: ""  
url: "[https://translate.google.com/translate\_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello](https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello)"  
statusCode: 200  
headers: object  
content-type: "audio/mpeg"  
cache-control: "no-cache, no-store, max-age=0, must-revalidate"  
pragma: "no-cache"  
expires: "Mon, 01 Jan 1990 00:00:00 GMT"  
date: "Mon, 13 Dec 2021 14:08:36 GMT"  
p3p: "CP="This is not a P3P policy! See [P3P and Google's cookies - Google Account Help](http://g.co/p3phelp) for more info.""  
content-security-policy: "require-trusted-types-for 'script';report-uri /_/TranslateApiHttp/cspreport, script-src 'report-sample' 'nonce-Lyv8scDErHIZC5WF9zHYRw' 'unsafe-inline';object-src 'none';base-uri 'self';report-uri /_/TranslateApiHttp/cspreport;worker-src 'self'"  
cross-origin-resource-policy: "cross-origin"  
cross-origin-opener-policy: "same-origin"  
transfer-encoding: "chunked"  
server: "ESF"  
x-xss-protection: "0"  
x-frame-options: "SAMEORIGIN"  
x-content-type-options: "nosniff"  
set-cookie: array[1]  
alt-svc: "h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43""  
connection: "close"  
x-node-red-request-node: "4326cab4"  
responseUrl: "[https://translate.google.com/translate\_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello](https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello)"  
redirectList: array[0]  
retry: 0  
responseCookies: object  
NID: object  
payload: ""  
rc: object  
code: 0  
13/12/2021, 14:08:38node: 1c579e8dcde38857  
msg : Object  
object  
 msgid: "3763f73409a045f9"  
topic: ""  
url: "[https://translate.google.com/translate\_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello](https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello)"  
statusCode: 200  
headers: object  
content-type: "audio/mpeg"  
cache-control: "no-cache, no-store, max-age=0, must-revalidate"  
pragma: "no-cache"  
expires: "Mon, 01 Jan 1990 00:00:00 GMT"  
date: "Mon, 13 Dec 2021 14:08:36 GMT"  
p3p: "CP="This is not a P3P policy! See [P3P and Google's cookies - Google Account Help](http://g.co/p3phelp) for more info.""  
content-security-policy: "require-trusted-types-for 'script';report-uri //TranslateApiHttp/cspreport, script-src 'report-sample' 'nonce-Lyv8scDErHIZC5WF9zHYRw' 'unsafe-inline';object-src 'none';base-uri 'self';report-uri /_/TranslateApiHttp/cspreport;worker-src 'self'"  
cross-origin-resource-policy: "cross-origin"  
cross-origin-opener-policy: "same-origin"  
transfer-encoding: "chunked"  
server: "ESF"  
x-xss-protection: "0"  
x-frame-options: "SAMEORIGIN"  
x-content-type-options: "nosniff"  
set-cookie: array[1]  
0: "NID=511=K1hvWZFJNwX6TAdr4ZHxOOiSrVJmVhx-CrkezP4YSSqvbIGUunkAlHONx0aS76oNljmBs006adUTC3F8BeOr2pe-VcgCPaUt9qPwcpH-CaSKeaydzA3e4btuVQNjpesBF9m6NOoO9N92UvH9o55xnxFj0889Sz1ZgWNvE\_ErI2g; expires=Tue, 14-Jun-2022 14:08:36 GMT; path=/; [domain=.google.com](http://domain=.google.com); HttpOnly"  
alt-svc: "h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43""  
connection: "close"  
x-node-red-request-node: "4326cab4"  
responseUrl: "[https://translate.google.com/translate\_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello](https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=Hello)"  
redirectList: array[0]  
retry: 0  
responseCookies: object  
NID: object  
expires: "Tue, 14-Jun-2022 14:08:36 GMT"  
path: "/"  
domain: ".google.com"  
value: "511=K1hvWZFJNwX6TAdr4ZHxOOiSrVJmVhx-CrkezP4YSSqvbIGUunkAlHONx0aS76oNljmBs006adUTC3F8BeOr2pe-VcgCPaUt9qPwcpH-CaSKeaydzA3e4btuVQNjpesBF9m6NOoO9N92UvH9o55xnxFj0889Sz1ZgWNvE\_ErI2g"  
payload: object  
code: 0

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 December 2021 14:50 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/9 "2021-12-13T14:50:34Z")

</div>

since you have already translated a word, you could add an inject directly to the `exec` node to play the file.

Have you inserted a set of headphons to the audio jace to see if you hear sound from them with the DISPLAY=:0 removed (copy the exec node to a seperate fow to experiment with)

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [13 December 2021 15:10 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/10 "2021-12-13T15:10:48Z")

</div>

I'm using raspberry pi zeros, so no headphone jack. I've used an inject node into the exec and it still needs the DISPLAY=:0 to work. Admittedly the output to Stdout and return code are much more succinct when using the inject node.

without DISPLAY=:0 the debug output is

13/12/2021, 15:09:23[node: 0873e50e140abde5](http://192.168.1.8:1880/#)msg : Object

object

\_msgid: "727da33416e68966"

topic: ""

payload: ""

rc: object

code: 0

13/12/2021, 15:09:23[node: 1c579e8dcde38857](http://192.168.1.8:1880/#)msg : Object

object

\_msgid: "727da33416e68966"

topic: ""

payload: object

code: 0

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 December 2021 15:23 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/11 "2021-12-13T15:23:18Z")

</div>

I assume you are using the 'Desktop' version of Buster on the PiZero. Is it a PiZero W model 1 or 2?

Were your prior installs of raspbian the desktop version too?

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [13 December 2021 15:35 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/12 "2021-12-13T15:35:20Z")

</div>

Yes desktop version of Buster. When it worked without DISPLAY=:0 on Stretch I was using version 1 of Node Red and PiZero W model 2. There has always been a delay in the bluetooth audio output via exec node, whereas from VNC Viewer using the terminal it is instant. I believe there was a change in BlueZ with Buster, but why node red should require DISPLAY=:0 for the exec node, I have no idea, but at least I managed to resolve the issue by it's inclusion. It would have been nice to have got a slicker response on the bluetooth output, but I guess it is what it is, and 5 sec is not too bad.

Thanks for your interest in trying to address the issue.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 December 2021 16:51 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/13 "2021-12-13T16:51:45Z")

</div>

You might try asking on the raspberrypi foundation’s forum.

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [13 December 2021 18:26 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/14 "2021-12-13T18:26:47Z")

</div>

True, perhaps I should raise a query there, but it does seem to be associated with a peculiarity as to how executable code in the terminal doesn't get implemented as expected in node red EXEC node.

---

<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 December 2021 19:08 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/15 "2021-12-13T19:08:46Z")

</div>

If you connect to the pi using SSH and run the command there, does it work?

---

<div class="post-metadata">

**Author:** ![PdeJ](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@PdeJ](https://discourse.nodered.org/u/PdeJ)\
**Post date:** [13 December 2021 22:43 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/16 "2021-12-13T22:43:58Z")

</div>

Yes,

> ffplay Desktop/audio.mp3 \>/dev/null 2\>&1 -vn -autoexit -nodisp ssh

works fine using ssh or via VNC Viewer, but in node red EXEC node requires prefixing with DISPLAY=:0

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 December 2021 22:44 UTC](https://discourse.nodered.org/t/command-works-in-terminal-but-not-in-exec-node/55087/17 "2021-12-27T22:44:22Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
