<p dir="auto">Electron Info</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;electron-devtools-installer&quot;: &quot;^1.1.2&quot;,
&quot;electron-packager&quot;: &quot;^7.0.2&quot;,
&quot;electron-prebuilt&quot;: &quot;^1.2.3&quot;,
&quot;electron-rebuild&quot;: &quot;^1.1.4&quot;,"><pre class="notranslate"><code class="notranslate">"electron-devtools-installer": "^1.1.2",
"electron-packager": "^7.0.2",
"electron-prebuilt": "^1.2.3",
"electron-rebuild": "^1.1.4",
</code></pre></div>
<ul dir="auto">
<li>Operating system: Mac 10.11.2</li>
</ul>
<p dir="auto">Problem:<br>
The following code snipped runs fine in development but does not execute when packaged.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const exec = require('child_process').exec;
exec('echo $NODEPATH', (function(error, stdout, stderr){
  this.log_info(&quot;hehe&quot;)
  if (error) {
    console.error(`exec error: ${error}`);
    return;
  }
  console.log(`stdout: ${stdout}`);
  console.log(`stderr: ${stderr}`);
}).bind(this));
"><pre class="notranslate"><code class="notranslate">const exec = require('child_process').exec;
exec('echo $NODEPATH', (function(error, stdout, stderr){
  this.log_info("hehe")
  if (error) {
    console.error(`exec error: ${error}`);
    return;
  }
  console.log(`stdout: ${stdout}`);
  console.log(`stderr: ${stderr}`);
}).bind(this));

</code></pre></div>
<p dir="auto">Any ideas why I can't execute system commands in Electron when the app is packaged?</p>
<ul dir="auto">
<li>Electron version: 0.30 - 1.0.1</li>
<li>Operating system: OSX Yosemite</li>
</ul>
<p dir="auto">I having a problem PATH using Electron in production. The problem I have is with "pdfinfo" (poppler). Poppler was installed with homebrew and it is in the PATH (I can execute "pdfinfo" from any folder in my terminal).</p>
<p dir="auto">When starting my Electron app from the command line, I have no problem at all with the PATH. This will work fine, and "pdfinfo" will be found and work correctly:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="./node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron ./"><pre class="notranslate"><code class="notranslate">./node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron ./
</code></pre></div>
<p dir="auto">It's only when I start my app in production (opening the Electron.app app icon like any normal app). When spawning "pdfinfo" in this scenario, i get this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="stderr stdout: /bin/sh: pfdinfo: command not found"><pre class="notranslate"><code class="notranslate">stderr stdout: /bin/sh: pfdinfo: command not found
</code></pre></div>
<p dir="auto">Notice the "/bin/sh" path.</p>
<p dir="auto">While looking for an explanation for this problem I stumbled upon this thread: <a href="https://discuss.atom.io/t/every-spawn-task-throws-enoent-when-electron-app-packaged-for-distribution/18692" rel="nofollow">https://discuss.atom.io/t/every-spawn-task-throws-enoent-when-electron-app-packaged-for-distribution/18692</a></p>
<p dir="auto">Read where "erikmellum" states:</p>
<blockquote>
<p dir="auto">When in production, spawn does not use your regular PATH variable to locate executables. It will basically use a PATH that includes OS bin folders (such as /usr/bin).</p>
</blockquote>
<p dir="auto">Which kinda seems to be related to my problem. Is this true? How can I get around this? Is there a way to tell production Electron to use the normal system PATH in production?</p>