Different results running command manually or in exec node

I'm trying to run a program with command line parameters put together by node red. When executed from node red I always get "File Not Found" (exit code 4) but if I run the exact same command from cmd.exe it works (exit code 0).

What are the differences in the environment between the two?

image

Thanks,
Richard

Put a debug node on each of the outputs of the exec node and also one on the node feeding the exec node so we can see what is going into it.

on windows you may need to use double \\ to escape the \ or use / instead.

I've tried with and without the escaping but the result is the same. It's not having any issues running the binary AFAICT. From the output it's auto-adding proper escaping.

Input to the exec node:

{"topic":"","ip":"::ffff:10.255.242.149","port":53619,"_session":{"type":"tcp","id":"a883dca.881792"},"_msgid":"d4ef1fea.d89e","columns":"asset,program","parts":{"id":"d4ef1fea.d89e","index":0,"count":1},"argument":{"asset":"3149-MAKINO MILL","program":"O00008888","server":"USMEMSMDBPVW19"},"arguments":"-a USMEMSMDBPVW19 -p \"3149-MAKINO MILL\" –r \"O00008888\""}

Output (stdout, exit code respectively, no output on stderr):

{"topic":"","ip":"::ffff:10.255.242.149","port":53619,"_session":{"type":"tcp","id":"a883dca.881792"},"_msgid":"d4ef1fea.d89e","columns":"asset,program","parts":{"id":"d4ef1fea.d89e","index":0,"count":1},"argument":{"asset":"3149-MAKINO MILL","program":"O00008888","server":"USMEMSMDBPVW19"},"arguments":"-a USMEMSMDBPVW19 -p \"3149-MAKINO MILL\" –r \"O00008888\"","payload":"","rc":{"code":4,"message":"Command failed: N:\\DNCMax8\\DNCMaxCtrl.exe -a USMEMSMDBPVW19 -p \"3149-MAKINO MILL\" –r \"O00008888\" -q\n"}}

{"topic":"","ip":"::ffff:10.255.242.149","port":53619,"_session":{"type":"tcp","id":"a883dca.881792"},"_msgid":"d4ef1fea.d89e","columns":"asset,program","parts":{"id":"d4ef1fea.d89e","index":0,"count":1},"argument":{"asset":"3149-MAKINO MILL","program":"O00008888","server":"USMEMSMDBPVW19"},"arguments":"-a USMEMSMDBPVW19 -p \"3149-MAKINO MILL\" –r \"O00008888\"","payload":{"code":4,"message":"Command failed: N:\\DNCMax8\\DNCMaxCtrl.exe -a USMEMSMDBPVW19 -p \"3149-MAKINO MILL\" –r \"O00008888\" -q\n"}}

I think that's the key here. You're probably in different accounts and have different privileges/access.

I'm somewhat new to running NodeRED on Windows but I don't think it's login related. I did a default install of NodeRED as a normal user so it's installed in my home directory and I'm running cmd.exe as the same user which is why I suspect an environment difference.

That being said in talking to the in house SME on this program it doesn't rely on any environment variables.

Try putting the command into the msg.arguments and remove it from the exec node so msg.argument will contain the full command and arguments. And try it with the forward slash

I tried the first part with the same result. I'm not sure what you mean by forward slash.

Can you try a simple exec of "dir n:" then "dir N:/DNCMax8" to check it can read that path

The "File not found" is a message I have constructed based off the exit code of the binary. DNCMaxCtrl.exe IS being run, but terminating with exit code 4, which means the program I am requesting is not found, but the process succeeds when run manually with the exact same command line options.

Maybe I should post a snapshot of the whole flow when I'm in front of my work computer.

I tried forward slashes with the same result. I also created a test exec node to list the directory and it succeeded.

What is this program that is not found? Does finding it involve finding a file? If so then how does the exe know where to find it?

It's a CNC machine program, essentially a text file that gets pushed to a network share. The executable knows the interworking of itself, I do not.

All I know is that when run manually from a cmd.exe window it works, and when I run the exact same command from an exec node, it always comes back exit code 4.

As @dceejay suggested before, what does dir n: give when executed by the exec node.

To add to that, what file name are you passing to this executable? If that file is also on a shared drive, try doing an exec node to list that directory.

I suspect the issue is with the command not knowing or able to access one or more network paths. Either due to permissions, environment or passing command line variables with single backslashes in the file path.

A simple test would be to put your exe in a local folder along with a file. Get it working locally first. Then try mapped drive names and even fully qualified unc paths.

Well the fact that the program can't find it when you run it from node-red but can when you run it from the command line appears to mean that the executable cannot find it. The executable may we use an environment variable to know where to look, or some other similar mechanism, and when you run it in node-red that is not setup correctly. You need to find more about how the executable finds the file.

I didn't post the results but I tried that, I got the full listing of the directory as expect.

The executable takes care of the "magic" The programs are stored in a specific location known to the server. I'm passing the main name "O00008888" but the actual file is "O00008888.PTP" but the system appends that automatically.

It seems the exec node has been updated to automatically correct the backslashes for windows, no matter if I put one, two, or a forward slash the debug output shows double backslashes.

I have since copied the executable to my C drive with the same results. I don't think just coping the program to the same folder will work. Cimco is a DNC server and knows where to look for the program based on the CNC machine configuration.

Can you show us what the debug node showing the input to the exec node looks like in a screenshot please.

Here's the debug input into the exec node:
image

If I remove -qand let the window pop up you can see the entries look correct, but shows the error File Not Found...

image

Here I run the exact same command from the cmd.exe window and get:

image

I've looked through my environment variables twice and don't see anything specific to this application. I'm running node-red as the same user.

Maybe I'll turn on verbose logging. The only other thing I can think of is somehow it's using a different character encoding?

HOLY CRAP I GOT IT!

So after changing my windows encoding to use Beta UTF-8, it still didn't work, but poking around the nodes a bit I noticed that the "hyphen" for the -r option was PHYSICALLY LONGER than the hyphen used for the -p option.

My assumption is that it was then ignoring the -r and thus was only looking for an exact match in the current directory instead of the search path for which is setup per port (the -p option).

So it looks like the dash/hyphen got swapped somehow but I couldn't see the difference until changing my encoding to UTF-8. My guess is it worked when copying and pasting to a command windows because it was being converted in the background.

WHEW!

2 Likes