Jiohn Dioe
Jiohn Dioe

Reputation: 111

NodeJs Error: spawn C:\Windows\system32\cmd.exe; ENOENT

This is my script :

var exec = require('child_process').exec;

    exec('dir', function(error, stdout, stderr) {  // 'dir' is for example
      if (error) {
        console.error(`exec error: ${error}`);
        return;
      }
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    });

And in the console I have :

exec error: Error: spawn C:\Windows\system32\cmd.exe; ENOENT

Someone can help me ?

Upvotes: 11

Views: 34069

Answers (4)

Abdul Samad
Abdul Samad

Reputation: 71

Increasing the maxBuffer solved the problem for me.

const child_process = require('child_process');

var command = 'git ls-files . --ignored --exclude-standard --others';

child_process.execSync(command, {
   maxBuffer: 1024 ** 6,
});

Upvotes: 0

Ruan
Ruan

Reputation: 4283

The problem for me was that my solution directory was on a different drive than windows. Creating my solution on my C drive solved the issue.

Upvotes: 0

hugeandy
hugeandy

Reputation: 223

This can also be caused if you are feeding in ExecOptions the options parameter, specifically 'cwd', and the path you provide is invalid

e.g:

cp.exec(<path_to_executable>, {
  cwd: <path_to_desired_working_dir>
}, (err, stdout, stderr) => {
  //......
})

If is not valid, the callback will be called with err equal to

Error: spawn C:\Windows\system32\cmd.exe ENOENT

Upvotes: 19

sudheer nunna
sudheer nunna

Reputation: 1719

I got to resolve the issue the problem is to remove the semicolon(;) from an end of the ComSpec path C:\Windows\System32\cmd.exe

Mycomputer>properties>Advance System Settings>Environment Variables>System Variables

add this path: enter image description hereComSpec C:\Windows\System32\cmd.exe

Upvotes: 10

Related Questions