Running script from exec node error

I have made a script to print pdf files to a network printer using pdf-to-printer. When I run the script directly in the command prompt, it works fine but when I try to run the same command from inside node red using the exec node, I get an error "Printing problem.: Printer with given name doesn't exist.
When I try to print to a local printer, everything works fine from within exec node.

Node Red is on version 3.1.0 running on Windows.

Where should I start looking to resolve this? What other info can i provide?
Any help would be appreciated.

This really should be an FAQ.

When you run exec under Node-RED, the shell has the settings of Node-RED (its parent) and not those of your user shell. So what works and what doesn't will depend greatly on how you start Node-RED. If you start it manually from a command line logged in with your normal user id, the exec shell should have the same settings as your normal user. However, if you start Node-RED some other way, there is a reasonable chance that it will have a different environment.

One way to easily tell, is to use exec to run the command set (if you are using command prompt, for PowerShell, you need Get-ChildItem Env:* or dir Env: or gci Env:). Then see what environment variables are set.

Firstly, i want to thank you for pointing me in the right direction. I am not an advanced user so i struggle a little.

I followed your suggestion and ran the command. What i noticed is the variables:

USERNAME=MPV-OFF$
USERPROFILE=C:\WINDOWS\system32\config\systemprofile

What I understand is that it is running under a systemprofile and not my user profile which is also different than my user name. Am i correct in this assumption?

Node Red is setup to start as a service on login, what should i change to ensure it starts under my user profile?

Looks like it.

Rather depends how you set it up but people normally use something like nssm.

If you look on its home page: NSSM - the Non-Sucking Service Manager

You will see a login tab and that is where you can set the user to run the service. Just note that, if you want the service to start and run even if nobody is logged onto the device, you will need to provide the password to the service setup. This isn't a major issue on Windows as it will store the password securely but obviously, you should use a user account that is just for Node-RED generally. You would probably want/need to set up a local user account for that purpose.

That's some great help. I'm looking into it right now. Thank you.

1 Like

I was able to resolve the issue thanks to your help.

I already had a node-red service which was starting it but it was running as a Local system account.
It turns out all I had to do was to go to the node-red service properties under Log On and select my user account and add my password.
Now the exec node runs the commands I need.

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