Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Windows, spawn.kill() doesn't kill child process #148

Open
localhosted opened this issue Dec 1, 2021 · 0 comments
Open

In Windows, spawn.kill() doesn't kill child process #148

localhosted opened this issue Dec 1, 2021 · 0 comments

Comments

@localhosted
Copy link

localhosted commented Dec 1, 2021

Trying to run a project that uses cross-spawn and in Windows spawn() spawns a cmd that the runs my command. When killing the spawned pid the node process doesn't die:

let node;

compiler.hooks.watchRun.tap("Dev", (compiler) => {
  console.log(`Compiling ${compiler.name} ...`);
  if (compiler.name === "server" && node) {
    // I added this to try and force kill the cmd instance, but it won't kill the child node process
    if (isWin) {
      spawn("taskkill", ["/pid", node.pid, "/F", "/T"]);
    }
    const r = node.kill();
    node = undefined;
  }
});

compiler.watch({}, (err, stats) => {
  if (err) {
    console.error(err);
    process.exit(1);
  }
  console.log(stats?.toString("minimal"));
  const compiledSuccessfully = !stats?.hasErrors();
  if (compiledSuccessfully && !node) {
    console.log("Starting Node.js ...");
    node = spawn(
      "node",
      ["--inspect", path.join(__dirname, "dist/server.js")],
      {
        stdio: "inherit",
      }
    );
  }
});

Switching to child_process works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant