Node red on Mac mini m2 starting as a service can't execute commands via exec node

Hello I've installed node-red on my macmini m2 running 15.4.1 Sequoia.

Everything is working fine - if is start NR by terminal (cmd node-red) the exec node is working as expected - commands are executed correctly.

But if NR is starting automatically on startup via LaunchAgent script - I'm facing a problem concerning permissions I guess, when I try to execute commands via the exec node.
The commands are not executed I recieve an error 127 e.g. /bin/sh: cp: command not found

Can someone point me to the right direction what I've to do ??

Thanks in advance

Hi @mac89muc

Welcome to the forums :smiley:

One potential, the cp command is a binary in it's own right, it's not built into the shell

It's very possible, the $PATH variable is not seen by the process (node)

The $PATH variable contains the location of /bin

Maybe try printing the $PATH variable using the exec node to check if this variable is seen

$PATH

A users shell, will envelop the $PATH variable, and will check these location(s) for commands.

I'm using an M2 Pro Mini.
But only Node RED on it for dev purposes

Try using the command
which cp
to give you the full path to the command, and put that in the exec node. On my Ubuntu system I see

which cp
/usr/bin/cp

If that doesn't help, how did you install node-red? Is it running in Docker for example? If so then it may be necessary to install cp in the container.

thank you guys - that solution with the full path in the exec command is working for me.

which cp is giving me /bin/cp
$PATH is containing /bin so is there a chance to give the node process access to the $PATH variable?

If I start nr by terminal command node-red I have no problems - only if I start the node-red process automatically by launch agent.

The problem is that when running automatically the PATH environment variable does not exist. I don't use Macs, but I expect that googling for something like
How to set an environment variable when starting with LaunchAgent
will help.

Though personally I would just use the full path rather than messing about with env vars.

Add this to your launch agent plist

<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
    <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin</string>
</dict>

@Colin's will work also, its just my preference to allow any launch agent's to see the path variable.

whatever works better for you.

its been a whilst since I done this, so research if committing to the above

source : launchd - How to extend PATH of LaunchAgents in ~/Library/LaunchAgents? - Ask Different