developerasun / myCodeBox-web

Open source code box for web developers.
Apache License 2.0
5 stars 0 forks source link

[BUG] Javascript/child process: spawn dir ENOENT #269

Open developerasun opened 2 years ago

developerasun commented 2 years ago

Describe the bug

Node.js child_process spawn method not working in Windows10

To Reproduce Steps to reproduce the behavior:

  1. Go to terminal
  2. Run app.js like below
"use strict";
const { spawn, exec } = require("child_process");

// The child_process.spawn() method spawns a new process using the givencommand,
// with command-line arguments in args.
// If omitted, args defaults to an empty array.
// spawn(command, [cli-options])
const child = spawn("dir", []);

child.stdout.addListener("data", (data) => {
  console.log("stdout: ", data);
});

child.stderr.addListener("data", (data) => {
  console.log("stderr: ", data);
});

child.addListener("error", (error) => {
  console.log(error.message);
});

child.addListener("exit", (exitCode, signal) => {
  if (exitCode) console.log(exitCode);
  if (signal) console.log("process killed with signal: ", signal);
  console.log("done");
});
  1. See error

Expected behavior

spawn child process runs a dir command in terminal

Screenshots

spawn-dir

Additional context Add any other context about the problem here.

Labeling Add a proper label for the issue