./ command in exec node

Hi!
I cannot get this working from node red...
when i run this "sudo ./fm_transmitter -f 102.7 acoustic_guitar_duet.wav" in the dir "/home/pi/fm_transmitter/"
It works on command line

but when i do the following from the exec node i get an error, what is run with my thinking??
"sudo ~/home/pi/fm_transmitter/fm_transmitter -f 102.7 acoustic_guitar_duet.wav"

i found that ./ is just the current directory, so i tried to run the commend in the directory without ./ but then it is also not working :frowning:

Thanks!

./ is a relative path so it will be a different path from wherever you are on the command line. Inside Node-RED, you are inheriting the location of Node-RED.

You should generally use absolute paths when working with files inside Node-RED.

Thanks!

so if i use ./ in folder xxx
Then it should be /home/pi/xxx ?
Is that correct because i tried that but that is not working

Or do i understand it wrong?

There should not be a ~ on the front.
So first check that running this in a terminal works (no ~)
sudo /home/pi/fm_transmitter/fm_transmitter -f 102.7 acoustic_guitar_duet.wav
If it does then does it ask for a password?

In fact you probably need to put the full path on the wav file too so
sudo /home/pi/fm_transmitter/fm_transmitter -f 102.7 /home/pi/fm_transmitter/acoustic_guitar_duet.wav

No, that would result in ./xxx

So if you started with /home/pi/xxx, ./ would be /home/pi/xxx.

./ is the current folder.

But when you run Node-RED, what is the "current" folder?

When you use a leading tilde ~/, that points to the current users home folder. So for the Pi user, that is /home/pi.

1 Like

when i run this in the correct folder the command below works
sudo /home/pi/fm_transmitter/fm_transmitter -f 102.7 acoustic_guitar_duet.wav

running from another folder or from the exec node it gives me the error that acoustic_guitar_duet.wav does not exist

maybe i need to put a path to the wav file too then?

Solved!

~ was the problem and the wav file needed a path too

Thanks!!

Does it run in the exec node too?

Yesssss :wink:

This is working in the exec node:
sudo /home/pi/fm_transmitter/fm_transmitter -f 102.7 /home/pi/fm_transmitter/acoustic_guitar_duet.wav

Does it not ask you for a password when you run it from the command line? If so then it should not work in an exec node.

Actually, you can use exec with sudo if you really must.

$echo <password> | sudo -S <command>

The -S parameter takes the password from stdin.

No need to add password. Works without it

That's horrible, putting the password in plain text in the flow file, though I suppose you could insist on it being entered via the dashboard each time which wouldn't be quite so bad.

Have you specifically disabled it for the node red user for that command or have you completely disabled password with sudo. If you have completely disabled it then I hope you realise the security implications of that.
An even better way is to give a particular user group access to whatever resources the command needs that normally requires sudo, then the node-red user would not need to use sudo with that command.

Ehhh is out of the box in this way.
Will have a look at it but its not my best skill :wink:

Haha, I did stress the if you really must part. Didn't say it was best, just that you can.

You can always use a credential and insert it to the flow data. That wouldn't be too bad, good enough for most things. I wouldn't have any exec nodes in flows that might be accessible from the Internet in any case.

That's true, I hadn't thought of that.

I thought raspbian had stopped allowing sudo without password, but maybe it is only on raspbian lite that this is true, or maybe I am completely wrong.
In practice it probably isn't much of an issue as long as nothing on your network (in particular node-red) is accessible from the internet, or by possibly malicious users via the wifi.

Well, it is just a setting away even if they have. I've not installed a Buster version of Rasbian so I don't know myself.

I'm moving onto Debian Buster on an old(ish) Lenovo x240 laptop. I finally outgrew my 2 Pi's. The alternative was a 4GB Pi 4 but it wasn't worth the money for me. 8GB RAM and an i5 makes a nice platform and not too power hungry as it is a slim laptop with the screen off and set to low-power CPU mode. :slight_smile: