pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Running child_process (spawn) through pm2 does not work

Open Mbensler opened this issue 3 years ago • 1 comments

What's going wrong?

I am running a script written in Javascript through PM2. In that script I am also calling a Python script to do something. The script works just fine running it through VS Code, however running it through PM2 gives me the following error:

Error: spawn python ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn python',
  path: 'python',
  spawnargs: [ 'pywinauto_login.py' ]
}

My child_process looks like this:

  // Python child process
  const python = spawn('python', [`pywinauto_login.py`], {cwd: 'C:\\Users\\kitt\\Documents\\ck\\'});
  python.on('close', (code) => {
    console.log('code');
  });

My working directory is: C:\Users\kitt\Documents\ck\

And the script im trying to run as a child process is found at: C:\\Users\\kitt\\Documents\\ck\\pywinauto_login.py

Supporting information

I've tried countless ways to make it work, and tried a ton of different ways to define the path, and they all work when run from the terminal or in vscode, but not with PM2

Also tried running everything as admin.

$ pm2 report

--- Daemon logs --------------------------------------------
C:\Users\kitt\.pm2\pm2.log last 20 lines:
PM2        | 2023-01-17T14:30:56: PM2 error: Error caught while calling pidusage
PM2        | 2023-01-17T14:30:56: PM2 error: Error: No matching pid found
PM2        | 2023-01-17T14:31:03: PM2 log: Stopping app:index id:0
PM2        | 2023-01-17T14:31:03: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2023-01-17T14:31:03: PM2 log: pid=9432 msg=process killed
PM2        | 2023-01-17T14:39:41: PM2 log: Process 0 in a stopped status, starting it
PM2        | 2023-01-17T14:39:41: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2023-01-17T14:39:41: PM2 log: App [index:0] online
PM2        | 2023-01-17T14:40:44: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2023-01-17T14:40:44: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2023-01-17T14:40:44: PM2 log: App [index:0] online
PM2        | 2023-01-17T14:41:53: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2023-01-17T14:41:53: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2023-01-17T14:41:53: PM2 log: App [index:0] online
PM2        | 2023-01-17T14:42:30: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2023-01-17T14:42:30: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2023-01-17T14:42:30: PM2 log: App [index:0] online
PM2        | 2023-01-17T14:42:35: PM2 log: Stopping app:index id:0
PM2        | 2023-01-17T14:42:37: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2023-01-17T14:42:37: PM2 log: pid=4152 msg=process killed

Mbensler avatar Jan 17 '23 14:01 Mbensler

I'm having the same issue, has anyone fixed it?

huntbbbilly avatar Jan 23 '24 02:01 huntbbbilly