# Exec command does not work like the same command in the cli

**URL:** <https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835>\
**Category:** General\
**Created:** [18 January 2022 04:04 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835 "2022-01-18T04:04:25Z")\
**Posts on this page:** 14\
**Page:** 1

<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:** [18 January 2022 04:04 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/1 "2022-01-18T04:04:25Z")

</div>

Ok, I've wasted too much time on this "espeak" exec node... has anyone seen this before?

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

This command works fine using my login from the command line on my rpi4 running ubuntu 10.20:

`srickus@shrpi4:~$ espeak -ven+f4 -k5 -s150 "testing 123"`

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [18 January 2022 04:15 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/2 "2022-01-18T04:15:13Z")

</div>

In my experience this means that the environment is different between you logged into your account and what NR is running in. Check user and group that NR is in and also dump the environment, like 'set; espeak -ven+f4 -k5 -s150 "testing 123"' and compare it to "set" run from your terminal. I'm not sure I have the quotes correct but I think you can work that out.

---

<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:** [18 January 2022 05:04 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/3 "2022-01-18T05:04:05Z")

</div>

Well, I thought you were onto something there -- it seems that my user needs to have access to the `audio` group. However, adding my login to that group and restarting node-red does not seem to change anything.

So perhaps I should punt... and ask this community if they have another solution for sending a text string payload to the rpi4 audio output (either hdmi or headphone jack)? There seem to be lots of solutions to playing audio files, or sending a string for Alexa to announce, but not much for native pi4 audio from a text string.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [18 January 2022 06:45 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/4 "2022-01-18T06:45:43Z")

</div>

Hello,  
You can use

> **[node-red-contrib-pico2wave](https://flows.nodered.org/node/node-red-contrib-pico2wave)**
>
> a simple wrapper around the pico2wave commandline tts tool for use in nodered

To generate text to speech audio directly from nodered on a pi and than use any of the audio playing nodes to play it. Quality with pico2wave should also be a lot cleaner than espeak.

Johannes

---

<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:** [18 January 2022 08:33 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/5 "2022-01-18T08:33:53Z")

</div>

Don't know if it makes a diff but I always put bash extra parameters like -ven etc in the command - not as a suffix.

I always add a space at the end as well

---

<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:** [18 January 2022 10:36 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/6 "2022-01-18T10:36:04Z")

</div>

This works for me

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de34731ef87ff37fdf333030179f391556f29d9c.png)

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [18 January 2022 17:11 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/7 "2022-01-18T17:11:38Z")

</div>

> [@shrickus](#):
>
> it seems that my user needs to have access to the `audio` group. However, adding my login to that group and restarting node-red does not seem to change anything.

I hope one of the suggestions has you working but in case not, I'll ask how you are running NR. Is it from a systemd service? If so, can we see the contents of the service file? Of particular interest are the "User=" and "Group=" lines under [Service]. If these don't specify your userid and group then NR is likely running as root and it won't get the same access your login has.

If you are running NR from your command line then you need to log out and back in before your audio group addition will take effect. But that raises the question of why you'd add yourself to the audio group if the command already worked from the command line without it?

---

<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:** [18 January 2022 17:39 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/8 "2022-01-18T17:39:02Z")

</div>

> [@LosinIt](#):
>
> I hope one of the suggestions has you working

Sorry, work is getting in the way so I've not had a chance to get back to sorting this out...

> [@LosinIt](#):
>
> Is it from a systemd service?

Yes, and the user and group are mine...

```auto
# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=srickus
Group=srickus
WorkingDirectory=/home/srickus

Environment="NODE_OPTIONS=--max_old_space_size=2048"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
# uncomment next line if you need to wait for time sync before starting
#ExecStartPre=/bin/bash -c '/bin/journalctl -b -u systemd-timesyncd | /bin/grep -q "systemd-timesyncd.* Synchronized to time server"'

ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
RestartSec=20
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

```

> [@LosinIt](#):
>
> why you'd add yourself to the audio group if the command already worked from the command line without it?

Good question... desparation?

---

<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:** [18 January 2022 17:42 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/9 "2022-01-18T17:42:15Z")

</div>

Ok, I think I see what you did there -- are those double quotes that you are using to surround the payload? And is this the way the `exec` node really works?!?

I guess I thought it was more sophisticated than just pasting some strings together before calling the command line processor, but perhaps not. What happens if the payload has double quotes inside it?

---

<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:** [18 January 2022 17:44 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/10 "2022-01-18T17:44:59Z")

</div>

It's just what I tried that works - your working command line shows quotes so I put them in in the exec node.

> [@shrickus](#):
>
> What happens if the payload has double quotes inside it?

No idea but not going to happen in this scenario 🙂

---

<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:** [18 January 2022 22:16 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/11 "2022-01-18T22:16:43Z")

</div>

Steve, what is in the msg payload going into the exec node? When you check off `+Append` msg.payload the format ot what gets used by the exec is

1. everything in `Command` (which could include options)
2. anything in msg.payload IF `+Append` is checked
3. anything in `extra input parameters`

---

<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:** [19 January 2022 04:22 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/12 "2022-01-19T04:22:16Z")

</div>

Thanks Paul, I tried as you and Simon suggested to try and insert the payload between double quotes after the command and options:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76f57023418921ae30279f62cebd9005022c588c.png)

SS, DD... ah well, it was worth the try.

> [@JGKK](#):
>
> Quality with pico2wave should also be a lot cleaner than espeak

Looks like this is my next best option -- even though I am not as keen on generating binary audio data and passing it to some player.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [19 January 2022 06:49 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/13 "2022-01-19T06:49:15Z")

</div>

It's not that bad 😉  
The audio that is generated by Pico2wave can be output as a buffer within the flow and passed directly to for example a sox play node. This way no audio gets actually saved on your device. Only difference would be that you have 2 instead of one node. And I think that is what espeak is doing behind the scenes anyway. They generate an audio buffer and than call some audio player library, you just don't get to see it.

---

<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:** [20 March 2022 06:49 UTC](https://discourse.nodered.org/t/exec-command-does-not-work-like-the-same-command-in-the-cli/56835/14 "2022-03-20T06:49:27Z")

</div>

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