# Different results running command manually or in exec node

**URL:** <https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234>\
**Category:** General\
**Created:** [15 April 2021 14:32 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234 "2021-04-15T14:32:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [15 April 2021 14:32 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/1 "2021-04-15T14:32:12Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8855aa8e0a6774d04cc30688aa6c5e8bda1cd97.png)

Thanks,  
Richard

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 April 2021 14:43 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/2 "2021-04-15T14:43:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 April 2021 14:45 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/3 "2021-04-15T14:45:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [15 April 2021 15:08 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/4 "2021-04-15T15:08:12Z")

</div>

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"}}`

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [15 April 2021 15:22 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/5 "2021-04-15T15:22:29Z")

</div>

> [@hobbes1069](#):
>
> What are the differences in the environment between the two?

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

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [15 April 2021 15:35 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/6 "2021-04-15T15:35:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 April 2021 00:49 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/7 "2021-04-16T00:49:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [16 April 2021 01:47 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/8 "2021-04-16T01:47:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 April 2021 06:31 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/9 "2021-04-16T06:31:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [16 April 2021 12:02 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/10 "2021-04-16T12:02:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [16 April 2021 12:09 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/11 "2021-04-16T12:09:53Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/427a44bdef57b80fcaed7807f702371bbd0380e4.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 April 2021 12:54 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/12 "2021-04-16T12:54:27Z")

</div>

> [@hobbes1069](#):
>
> DNCMaxCtrl.exe IS being run, but terminating with exit code 4, which means the program I am requesting is not found,

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?

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [16 April 2021 17:30 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/13 "2021-04-16T17:30:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 April 2021 17:43 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/14 "2021-04-16T17:43:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 April 2021 21:06 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/15 "2021-04-16T21:06:58Z")

</div>

> [@hobbes1069](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [16 April 2021 22:19 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/16 "2021-04-16T22:19:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 April 2021 06:41 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/17 "2021-04-17T06:41:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [19 April 2021 16:07 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/18 "2021-04-19T16:07:26Z")

</div>

Here's the debug input into the exec node:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d0907244f7b92db7643f75d40068a481e98cc597.png)

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [19 April 2021 17:36 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/19 "2021-04-19T17:36:15Z")

</div>

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/8079d3d59358abb2f83d135c607a3a993589e880.png)

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c03d7d4698d0f7552388f25d0a4c8a1c7dd8a97f.png)

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?

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [19 April 2021 18:12 UTC](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234/20 "2021-04-19T18:12:29Z")

</div>

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!

[Next page](https://discourse.nodered.org/t/different-results-running-command-manually-or-in-exec-node/44234.md?page=2)
