<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[child_process won't execute]]></title><description><![CDATA[<p dir="auto">I’m trying to execute a python script using the child_process. However my function doesn’t seem to be triggering.</p>
<pre><code>const spawn = require("child_process").spawn
var NodeHelper = require("node_helper")
const process = spawn("python3", ["return_something.py"])

module.exports = NodeHelper.create({
  start: function() {
    this.countDown = 10000000
  },
  socketNotificationReceived: function(notification, payload) {
      switch(notification){
          case "DO_YOUR_JOB":
            console.log(payload)
            this.sendSocketNotification("I_DID", (this.countDown - payload))
            break
          case "RETRIEVE_DATA":
            console.log(payload)
            this.job()
            break
      }
  },
  job: function(){
    console.log("I'm trying to retrieve data")
    process.stdout.on('data', (data)=&gt;{
      //********everything works up till here
        console.log("inside")
      var result = String.fromCharCode.apply(null, new Uint16Array((data)))
      this.sendSocketNotification("DATA_RETRIEVED", result)
    })
  }
})
</code></pre>
<p dir="auto">Python script.</p>
<pre><code>import sys

print("Hello, I'm Amira")

sys.stdout.flush()
</code></pre>
]]></description><link>https://forum.magicmirror.builders/topic/12469/child_process-won-t-execute</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 09:52:44 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/12469.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Apr 2020 04:34:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 16:01:22 GMT]]></title><description><![CDATA[<p dir="auto">Thank you all for all your wonderful suggestions. I’m able to run my python script successfully now. Thanks!</p>
]]></description><link>https://forum.magicmirror.builders/post/71691</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71691</guid><dc:creator><![CDATA[Temisola1]]></dc:creator><pubDate>Thu, 02 Apr 2020 16:01:22 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 13:58:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> I just want to recommend the <a href="https://www.npmjs.com/package/execa" target="_blank" rel="noopener noreferrer nofollow ugc">execa</a> package as it solves some issues with “child_process,” like cleaning up when the process exits.</p>
]]></description><link>https://forum.magicmirror.builders/post/71674</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71674</guid><dc:creator><![CDATA[joshwilsonvu]]></dc:creator><pubDate>Thu, 02 Apr 2020 13:58:58 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 12:21:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/temisola1" aria-label="Profile: Temisola1">@<bdi>Temisola1</bdi></a> said in <a href="/post/71635">child_process won't execute</a>:</p>
<blockquote>
<p dir="auto">after running successfully a few times it now returns</p>
</blockquote>
<p dir="auto">u need to cleanup when the invoked process  ends</p>
<pre><code>process.on('exit', function() {
  if (x) {
    x.kill();
  }
});
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/71662</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71662</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 02 Apr 2020 12:21:35 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 11:38:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/temisola1" aria-label="Profile: Temisola1">@<bdi>Temisola1</bdi></a> the node_helper doesn’t know where it is…  but the Modulename does…</p>
<p dir="auto">this.path</p>
<p dir="auto">so, you can add that to the config info you send down in the typical</p>
<p dir="auto">sendSocketNotification(“somevalue”, this.config)</p>
<p dir="auto">to pass parameters to the node_helper</p>
]]></description><link>https://forum.magicmirror.builders/post/71658</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71658</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 02 Apr 2020 11:38:20 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 05:44:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> after running successfully a few times it now returns Buffer 48 45 5c… or something that looks like hexadecimal code</p>
]]></description><link>https://forum.magicmirror.builders/post/71635</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71635</guid><dc:creator><![CDATA[Temisola1]]></dc:creator><pubDate>Thu, 02 Apr 2020 05:44:54 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 05:27:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> So I tried putting in the full path in my node_helper as opposed to relative path and that seemed to work. is there a way I can log the current directory in nodejs. It seems that’s the issue</p>
]]></description><link>https://forum.magicmirror.builders/post/71633</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71633</guid><dc:creator><![CDATA[Temisola1]]></dc:creator><pubDate>Thu, 02 Apr 2020 05:27:43 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 05:15:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> said in <a href="/post/71631">child_process won't execute</a>:</p>
<blockquote>
<p dir="auto">node testit.js</p>
</blockquote>
<p dir="auto">Yes, that works in the console.</p>
]]></description><link>https://forum.magicmirror.builders/post/71632</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71632</guid><dc:creator><![CDATA[Temisola1]]></dc:creator><pubDate>Thu, 02 Apr 2020 05:15:02 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 04:57:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/temisola1" aria-label="Profile: Temisola1">@<bdi>Temisola1</bdi></a> if you run this does it work from the terminal window?</p>
<p dir="auto"><a href="http://testit.py" target="_blank" rel="noopener noreferrer nofollow ugc">testit.py</a></p>
<pre><code>import sys 
# Takes first name and last name via command  
# line arguments and then display them 
print("Output from Python") 
print("First name: " ) 
print("Last name: " ) 
</code></pre>
<p dir="auto">testit.js</p>
<pre><code>  var spawn = require("child_process").spawn; 

    // Parameters passed in spawn - 
    // 1. type_of_script 
    // 2. list containing Path of the script 
    //    and arguments for the script  

    // E.g : http://localhost:3000/name?firstname=Mike&amp;lastname=Will 
    // so, first name = Mike and last name = Will 
    var process = spawn('python3',["./testit.py"]); 
   //                         req.query.firstname, 
     //                       req.query.lastname] ); 
  
    // Takes stdout data from script which executed 
    // with arguments and send this data to res object 
    process.stdout.on('data', (data)=&gt; { 
        console.log("received " +data); 
    } ) 
</code></pre>
<p dir="auto">works for me… (note python script path is ./, make sure u have right path to py file)</p>
<p dir="auto">then do<br />
node testit.js</p>
]]></description><link>https://forum.magicmirror.builders/post/71631</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71631</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 02 Apr 2020 04:57:54 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 04:48:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> That is correct. It works up till that point.</p>
]]></description><link>https://forum.magicmirror.builders/post/71630</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71630</guid><dc:creator><![CDATA[Temisola1]]></dc:creator><pubDate>Thu, 02 Apr 2020 04:48:35 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 04:48:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/temisola1" aria-label="Profile: Temisola1">@<bdi>Temisola1</bdi></a> i will look at it in the morning…</p>
<p dir="auto">you are seeing the “I’m trying to retrieve data”</p>
<p dir="auto">in the terminal window where you did npm start, right?</p>
]]></description><link>https://forum.magicmirror.builders/post/71629</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71629</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 02 Apr 2020 04:48:04 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 04:46:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> thanks for the response. that doesn’t seem to be working either.<br />
Is there something I need to install to be able to use stdout?</p>
]]></description><link>https://forum.magicmirror.builders/post/71628</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71628</guid><dc:creator><![CDATA[Temisola1]]></dc:creator><pubDate>Thu, 02 Apr 2020 04:46:27 GMT</pubDate></item><item><title><![CDATA[Reply to child_process won't execute on Thu, 02 Apr 2020 04:44:16 GMT]]></title><description><![CDATA[<p dir="auto">how about like this</p>
<pre><code>const spawn = require("child_process").spawn
var NodeHelper = require("node_helper")


module.exports = NodeHelper.create({
  start: function() {
    this.countDown = 10000000
  },
  socketNotificationReceived: function(notification, payload) {
      switch(notification){
          case "DO_YOUR_JOB":
            console.log(payload)
            this.sendSocketNotification("I_DID", (this.countDown - payload))
            break
          case "RETRIEVE_DATA":
            console.log(payload)
            this.job()
            break
      }
  },
  job: function(){
    console.log("I'm trying to retrieve data")
   var process = spawn("python3", ["return_something.py"])
    process.stdout.on('data', (data)=&gt;{
      //********everything works up till here
        console.log("inside")
      var result = String.fromCharCode.apply(null, new Uint16Array((data)))
      this.sendSocketNotification("DATA_RETRIEVED", result)
    })
  }
})
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/71627</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71627</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 02 Apr 2020 04:44:16 GMT</pubDate></item></channel></rss>