# Problem with exec node

**URL:** <https://discourse.nodered.org/t/problem-with-exec-node/11014>\
**Category:** General\
**Created:** [10 May 2019 22:38 UTC](https://discourse.nodered.org/t/problem-with-exec-node/11014 "2019-05-10T22:38:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike67](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mike67](https://discourse.nodered.org/u/mike67)\
**Post date:** [10 May 2019 22:38 UTC](https://discourse.nodered.org/t/problem-with-exec-node/11014/1 "2019-05-10T22:38:19Z")

</div>

Hello  
I think I have problem with the exec node.  
I don't get the same result when I use the same command in an exec node or in the putty console.  
For example, I try to use ngrok. (but I don't use the ngrok node, because that doesn't work at all, but this is an other topic)  
my working directory is /opt/plcnext  
In this directory, there is my application ngrok, and some dependent directory /.ngrok and /.ngrok2  
When I run the command : `/opt/plcnext/ngrok http https://localhost:8081` (this is a command to expose my port 8081 in https to the web), the result is correct, and I get a correct answer.  
When I use exactly the same command in an exec node, the answer returned by ngrok is different, and unfortunately, it stops my process.  
My node 🙂  
`[{"id":"341023e0.15f71c","type":"exec","z":"97efe9eb.ab5778","command":"/opt/plcnext/ngrok http https://localhost:8081","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":true,"name":"Envoi commande de publication","x":470,"y":140,"wires":[["bea63b85.69e798"],["bea63b85.69e798"],["bea63b85.69e798"]]}]`

My command line 🙂  
`/opt/plcnext/ngrok http https://localhost:8081`

Can it be that both commands are not interpreted in the same way, depending if they are coming from the console or from Node Red?  
Please notice that I have installed nodered with 'npm install -g node-red' command. Is this correct?

I also use an othe exec node, to register an url on google actions, and the behavior is different if I send the command from the exec node of node-red or from the console. I don't get the same result.  
what can it be?

I use NR 0.20.5, node.js 10.15.3, and my OS is Linux 4.14.63-rt40-pxc arm LE  
Thanks for your help

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 May 2019 06:14 UTC](https://discourse.nodered.org/t/problem-with-exec-node/11014/2 "2019-05-11T06:14:56Z")

</div>

Please post the output from both the commandline and node red, so that we can see the difference.

And yes they can be different as you may use a different shell. Also you are using `spawn` so it keeps running, correct ?

To install (correctly) use:  
`bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)`  
As per documentation.

---

<div class="post-metadata">

**Author:** ![mike67](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mike67](https://discourse.nodered.org/u/mike67)\
**Post date:** [11 May 2019 13:23 UTC](https://discourse.nodered.org/t/problem-with-exec-node/11014/3 "2019-05-11T13:23:17Z")

</div>

Hello, and thanks for your reply

I will make a snapshot ASAP to show the different results of the CLI and the Node.

What about the link you sent me?

So I have to use it as it is, or do I have to adapt it?

I made a test with an other nodered install, WICH is running on a Linux PC.

There, with the command top, I have seen that nodered is ran by the admin user. In my PLC where I have a problem, I can see that nodered is ran as Root user.

CAN this be the reason of the differences of behaviour?

If yes, how can I make nodered run as admin instead of root? For information, nodered is started automatically with a script.

Envoyé de mon iPhone

---

<div class="post-metadata">

**Author:** ![mike67](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mike67](https://discourse.nodered.org/u/mike67)\
**Post date:** [11 May 2019 21:27 UTC](https://discourse.nodered.org/t/problem-with-exec-node/11014/4 "2019-05-11T21:27:18Z")

</div>

I found a beginning of solution.  
I discovered that node-red is autostarted ([with my startup script](https://www.plcnext-community.net/index.php?option=com_content&view=article&id=379:how-to-start-node-red-automatically-on-boot-using-init-d&lang=en)) as root.  
And when I tried to use ngrok, an auth mecahnism was necessary.  
When I did this in the console, I was as Admin. But even if the auth token was present, it was not taken in account when the command was coming from node-red with the exec node, as root.  
so I have changed the way to make the auth, and logged as root in the console, and there it worked.

But my second problem is with an application called gactions. I use it to create and publish my google action.  
So, I made some chnages in my file settings, so that the gaction file is now owned by the root, instead of the admin.  
But, when i launch the application in the console as root, I get a correct reply 🙂

```auto
root@axcf2152:/opt/plcnext/# /opt/plcnext/gactions test -preview_mins 9999999 -action_package /opt/plcnext/action1.json -project my-test-app-12345
Pushing the app for the Assistant for testing...
Your app for the Assistant for project my-test-app-d13de is now ready for testing on Actions on Google enabled devices or the Actions Web Simulator at https://console.actions.google.com/project/my-test-app-12345/simulator/

```

This is a correct result

But when I send the same command using the exec node, I get this reply 🙂  
11/05/2019 à 23:24:53[node: 7b39c83b.d95988](http://192.168.1.52:1880/#)msg : Object

```auto
object

payload: "Pushing the app for the Assistant for testing...↵"

_msgid: "f67910a9.5eb5a"

11/05/2019 à 23:24:53[node: 7b39c83b.d95988](http://192.168.1.52:1880/#)msg : Object

object

payload: "Gactions needs access to your Google account. Please copy & paste the URL below into a web browser and follow the instructions there. Then copy and paste the authorization code from the browser back here.↵Visit this URL: ↵ https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=111111111111-o6vu1tjkq8oqjub8jilj6v1111111111.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Factions.builder&state=state ↵Enter authorization code: ↵"

_msgid: "f67910a9.5eb5a"

```

So, we can see here that instead of accepting the connection, Gaction requests a registration token.

why can there be a such behaviour difference, while the user and the command are the same?

---

<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:** [12 May 2019 05:53 UTC](https://discourse.nodered.org/t/problem-with-exec-node/11014/5 "2019-05-12T05:53:25Z")

</div>

Rather than trying to run everything as root, did you try changing your autostart script to run as admin ?

---

<div class="post-metadata">

**Author:** ![mike67](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mike67](https://discourse.nodered.org/u/mike67)\
**Post date:** [12 May 2019 12:56 UTC](https://discourse.nodered.org/t/problem-with-exec-node/11014/6 "2019-05-12T12:56:51Z")

</div>

HI

Yes I tried, but in that case, nodered doesn’t start anymore

I have use a croit in WICH it is written user=root, so I modified it to user =admin, but it seems that the script is either not taken in account or not working properly after reboot.

Thé script I used is here:

[https://www.plcnext-community.net/index.php?option=com\_content&view=article&id=379:how-to-start-node-red-automatically-on-boot-using-init-d&catid=78&Itemid=366&lang=en](https://www.plcnext-community.net/index.php?option=com_content&view=article&id=379:how-to-start-node-red-automatically-on-boot-using-init-d&catid=78&Itemid=366&lang=en)

Do you see something else to change in the script file so that nodered is started as admin?

Envoyé de mon iPhone

---

<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:** [12 May 2019 14:17 UTC](https://discourse.nodered.org/t/problem-with-exec-node/11014/7 "2019-05-12T14:17:03Z")

</div>

No - only the line user=root . But then again I don't know the plc or how else they may have restricted the admin user - they may not have access to run node-red. But if you can run node-red command from the admin command line then it should be possible to make it work...  
Then again the line with the userdir '/opt/plcnext/.node-red' - that must also be read write accessible to admin so it can save the flow files etc.
