Search code examples
javanode.jsprocessoperating-system

NodeJS child_process.spawn - process pid is missing


I can't determine whose side the problem is, either the Windows OS or Nodejs. Maybe you will have some ideas.

There is a nodejs application, it launches a java application through cmd:

process.env.JAVA_HOME = jreDir;

const p = child_process.spawn(
              'cmd.exe',
              ['/c', 'embedded.bat'], // bat file runs a java.exe with specified classpath and main class
              {
                env: process.env,
                cwd: dirname + '/server/bin'
              }
            );

In a normal situation

p.pid // has an identifier

This code works for most users on both Windows and macOS (on macos we use a slightly different script but also with child_process.spawn)

But for one person on Windows 10

p.pid // undefined

And if we manually run the java process (embedded.bat with cmd), then everything is fine, java process started correctly. The person has antivirus, but we tried to run it in windows safe mode, there is the same problem.

Can some software in the Windows 10 OS block (not allow) the launch of a process by another process?


Solution

  • The actual problem was the missing cmd.exe in the system variable $PATH.