# Parse specific text from payload in Node-Red?

**URL:** https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708
**Category:** General
**Created:** [28 October 2022 06:47 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708 "2022-10-28T06:47:02Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [28 October 2022 06:47 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708/1 "2022-10-28T06:47:02Z")

</div>

Hi all,

I have a small task but it is a bit too tricky for me 🙂

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f695d3878e374ec0d0f8e1cb54f9358f1e5ae6aa.png)

I am running a script from an EXEC Node that sometimes failes (once a day).  
In these cases I have to find out the ID of this script (using ps -ef | grep python) manually and stop it with a KILL command and simply restart the Script via EXEC Node.  
Now I would like to automatize this Auto-Kill and Auto-Restart

I have the ID already in this payload field, now the question is to get exactly this value into a variable

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

It always has to be the ID before the EVN.py script, but I do not yet know how to read this value.

Do you have a hint for me ?

BR  
Gawan

---

<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: [28 October 2022 07:08 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708/2 "2022-10-28T07:08:47Z")

</div>

> [@Gawan](#):
>
> now the question is to get exactly this value into a variable

Use a status node pointed at the exec node.

connect a debug (set to show complete message) - you will find the status value.

Then in a function node, if it starts `pid:` then split it on `:` and get the value from element `[1]`

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [28 October 2022 07:24 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708/3 "2022-10-28T07:24:27Z")

</div>

I added the status-node like this:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e759e687de2d224462cb18c1bfd8e3594198a37a.png)

now it seems that the Raspberry Pi is down and cannot be reached any longer. I have to tell my friend to reboot it 🙂

---

<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: [28 October 2022 07:30 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708/4 "2022-10-28T07:30:18Z")

</div>

> [@Gawan](#):
>
> I added the status-node like this

um why?

You have created a loop

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

Start node-red with the `--safe` flag to fix it.

* * *

When I said

> [@Steve-Mcl](#):
>
> Use a status node pointed at the exec node.

I did NOT mean "connected" - when you setup the status node you "point" it at a node to watch its status.

---

<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: [28 October 2022 08:25 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708/5 "2022-10-28T08:25:20Z")

</div>

> [@Gawan](#):
>
> I have to find out the ID of this script (using ps -ef | grep python) manually and stop it with a KILL command and simply restart the Script via EXEC Node.

You don't need the ID. If you send a message into the exec node with `msg.kill` set to `true` then it will kill the current process. For more information see the help text for the node.

---

<div class="post-metadata">

### Author: ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)
#### Post date: [28 October 2022 17:06 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708/6 "2022-10-28T17:06:23Z")

</div>

So this one specific EXEC node is always linked to one process ?

What if I trigger the node several times from different sources ?  
Which one will be killed if I send a "msg.kill" ?

---

<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: [28 October 2022 17:59 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708/7 "2022-10-28T17:59:04Z")

</div>

> [@Gawan](#):
>
> What if I trigger the node several times from different sources ?  
> Which one will be killed if I send a "msg.kill" ?

If you have several instances running at once from the same exec then I guess you _will_ have to provide the PID in `msg.pid`. Are you running several instances in parallel? You will also have trouble picking up the PID from the status in that case. How will you know which one is the one giving the problem?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [27 December 2022 17:59 UTC](https://discourse.nodered.org/t/parse-specific-text-from-payload-in-node-red/69708/8 "2022-12-27T17:59:10Z")

</div>

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