question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

child process `exec` blocks several minutes since v0.62.0

See original GitHub issue

NWJS Version : 0.62.0, (no error in 0.61.0) Operating System : MacOS 11.6.4 (Big Sur), Mac OS 12.2.1 (Monterey), Windows 10

Expected behavior

exec('ls', {timeout: 2000}, callback); should return immediately and invoke the callback with the result in stdout within 1 or 2 seconds.

Actual behavior

exec('ls', {timeout: 2000}, callback); blocks the entire process for a few minutes and invokes the callback with the result in stdout also just after a few minutes

How to reproduce

  1. open the developer console.
  2. enter the code.
const exec = nw.require('child_process').exec;
exec('ls', {timeout: 2000}, (error, stdout) => {
    if (error) { 
      alert(error.message);
    }
    else {
     console.log(stdout);
   }
});

With nwjs v0.62.0 the dev console is blocked for a few minutes. With v0.61.0 there is no such blocking.

19:45:22.815 exec('ls', {timeout: 2000}, (error, stdout) => { console.log(stdout);});
19:47:18.252 ChildProcess {_events: {…}, _eventsCount: 2, _maxListeners: undefined, _closesNeeded: 3, _closesGot: 0, …}
19:47:18.276 empty.html package.json

Example Project

package.json

{
  "name": "test-child-process",
  "version": "1.0.0",
  "main": "index.html",
  "window": {
    "width": 800,
    "height": 800,
    "id":"hello-nwjs-test-app",
    "title": "Hello NWJS!"
  }
}

index.html

<!DOCTYPE html>
<html lang="DE">
<head>
   <style>
      .files {
         white-space: pre;
      }
   </style>
</head>
<body>
	<h2>Files:</h2>
   <div class="files"></div>
   
   <script>
      const 
         exec = nw.require('child_process').exec;
         cmd = process.platform === "win32" ? "dir" : "ls";
      
      exec(cmd, {timeout: 2000}, (error, stdout) => {
          if (error) { 
              alert(error.message);
          }
          else {
             document.querySelector('.files').textContent = stdout;
          }
      });
   </script>
</body>
</html>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rogerwangcommented, Mar 10, 2022

This is fixed in git and will be available in the next nightly build.

0reactions
semmelcommented, Mar 14, 2022

Works great in v0.62.1 on MacOS and Windows 10! Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Child process | Node.js v19.3.0 Documentation
exec () : spawns a shell and runs a command within that shell, passing the stdout and stderr to a callback function when...
Read more >
NW.js v0.62.1 Released with Node.js v17.7.1 and Chromium ...
NW.js 0.62.1 is here with Node.js v17.7.1 and Chromium update. ... Fix: child process exec blocks several minutes since v0.62.0 (#7851).
Read more >
nodejs child_process child process run twice - Stack Overflow
In nodejs, i create a child process to execute a cmd command.It executed successfully,but after two minutes, it execute again.
Read more >
Flux release notes | Flux 0.x Documentation
Bug fixes. Update the toUInt() test to use the correct conversion behavior. Prevent the Flux formatter from losing precision on float values.
Read more >
Think Java - Green Tea Press
ˆ Muhammad Saied translated the book into Arabic and found several errors in the process. ˆ Marius Margowski found an inconsistency in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found