Command fails in "exec" but works in terminal

Hello,

I'm new to node-red and the Raspberry Pi that I'm running it on.

I have a flow that is designed to play an audio file using VLC. It worked until I needed to reinstall RPi due to a faulty SD card. I've created a simple flow to isolate the issue.

image

The inject payload is this string bash -c "exec -a testPID cvlc /home/pi/Music/ting.mp3"

The exec node (bash) command is empty but appends msg.payload

There are no deployment errors.

When I inject, no sound is played and the debug pane shows the following errors.
[017a7758] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[017e14f8] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11[017e14f8] main interface error: no suitable interface module
[0172cb58] main libvlc error: interface "dbus,none" initialization failed
[017cc2e0] main interface error: no suitable interface module[0172cb58] main libvlc error: interface "globalhotkeys,none" initialization failed
[017cc2e0] dummy interface: using the dummy interface module...

But, if I copy and paste the same line into a terminal, it works correctly;

This looks as if it may be some sort of configuration problem. But I'm struggling to find the problem with my limited experience of node-red, Linux and all things Pi . Despite a lot of Googling.

I've pasted the simple flow below.

I would appreciate any pointers.

John

EDIT: I've just realised a very similar question was posted a couple of hours previously. I'll keep an eye on those eplies also. Pulseaudio and musicplayer

[{"id":"7ddb98ac.770a78","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"fea64c4d.e4b95","type":"debug","z":"7ddb98ac.770a78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":60,"wires":},{"id":"d2b0ee6e.c9cee","type":"inject","z":"7ddb98ac.770a78","name":"","topic":"","payload":"bash -c "exec -a testPID cvlc /home/pi/Music/ting.mp3"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":60,"wires":[["481efec8.c876a"]]},{"id":"481efec8.c876a","type":"exec","z":"7ddb98ac.770a78","command":"","addpay":true,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"bash","x":290,"y":60,"wires":[["fea64c4d.e4b95"],["fea64c4d.e4b95"],["fea64c4d.e4b95"]]}]

To be honest, you may be lucky you got sound to work at all. For reasons that are well beyond me, my cleanly installed Lenovo laptop with Debian utterly refuses to make even a beep.

I've never had any luck with Linux sound, it seems OK if it just works but otherwise it is so arcane that I have no hope. One of many reasons that I won't use it as a working desktop, only as a server.

Hope someone more knowledgeable and clever than I can help.

Have you tried if this problem playing audio is vlc specific?
Could you install mpg123 and try playing the audio with that from an exec node? Just to narrow down the causes.
@TotallyInformation i agree audio on linux can be highly confusing :flushed:

I think this may be one of those situations where you need something like
export DISPLAY=:0
in the script, though I don't know much about what that does. If you search the forum for
export display
you will find a number of hits which may help explain it.

1 Like

Thanks for the suggestions.

JGKK, I tried with mplayer and got the same result.

Colin, that seems to fix it with both mplayer and vlc. I'm using this scrip;
bash -c "DISPLAY=:0 exec -a testPID cvlc /home/pi/Music/ting.mp3"

Tomorrow, I'll do some more Googling in an attempt to understand it.

Many thanks to all.

John

Hi There,

It seems I have sort of the same problem playing a video file with the exec node.
From command line it runs perfect.
Could you describe the script?
is it a script in a folder you call with the exec node?
or is the script in a node within node-red?

cvlc --play-and-exit --no-video-title --fullscreen /home/pi/Videos/videofile.mp4

is the command line command that works.

I think the reason your method doesn't work is because there is no X-Window associated with the command. VLC needs an X-Window to work.

I understand that it is possible to set-up a global environment variable to fix that but I don't know the method.

What I do is run it as a bash scrip and explicitly export the X-Window assignment. (Note: some of this terminology may be inaccurate; I'm still learning.)

As always there are a couple of ways to do it. My method is as follows;

The payload for the inject node is
bash -c "DISPLAY=:0 exec cvlc --play-and-exit --no-video-title --fullscreen /home/pi/Videos/videofile.mp4"

The payload for the exec node is empty.
The exec node is set to append the incoming payload.

That's it!

If you copy and import the flow below, you can test my method.

[{"id":"929c45db.a177f8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"6c084634.c419a8","type":"exec","z":"929c45db.a177f8","command":"","addpay":true,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"empty exec node","x":630,"y":220,"wires":[["7415f1f.2956d1"],["7415f1f.2956d1"],["7415f1f.2956d1"]]},{"id":"7415f1f.2956d1","type":"debug","z":"929c45db.a177f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":960,"y":220,"wires":[]},{"id":"74f697e3.34e5e8","type":"inject","z":"929c45db.a177f8","name":"Inject script as string","topic":"","payload":"bash -c \"DISPLAY=:0 exec cvlc --play-and-exit --no-video-title --fullscreen /home/pi/Videos/videofile.mp4\"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":330,"y":220,"wires":[["6c084634.c419a8"]]}]
1 Like

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