0

I'm creating a child process using "fork" in the "electron" app. I'm creating child process as below:

   const child_process_file = path.join(__dirname, 'getSubFolders.js')
   const sub = fork(child_process_file, [JSON.stringify(subFolderObj), JSON.stringify(arg)]) 

when I run this program in debug mode, the child process is working fine, but when I generate an exe file and run the exe file, child process is not working as it should be. It is targetting main.ts(main file) instead of a file('getSubFolders.js' here) passed in params while creating child process.

path generated for child_process_file is => C:\Users\Saurabh\AppData\Local\Programs\INSTALLED_EXE_PATH\resources\app.asar\two-way-sync\getSubFolders.js

can anyone suggest what am i doing wrong in this?

  • __dirname is not defined? Can u console log the full path child_process_file in both debug as well as release mode. – Shirshak55 May 23 '22 at 14:03
  • @Shirshak55 __dirname gives us current working directory debug "child_process_file" path => D:\CODE_PATH\two-way-sync\getSubFolders.js exe "child_process_file" path => C:\Users\Saurabh\AppData\Local\Programs\INSTALLED_EXE_PATH\resources\app.asar\two-way-sync\getSubFolders.js – Saurabh Beladiya May 24 '22 at 05:09

1 Answers1

0

I got a solution and it is working for me.

const env = { ...process.env, PATH: `${process.env.PATH}:/usr/local/bin` };
const child_process_file = path.join(__dirname, 'getSubFolders.js')
const sub = fork(child_process_file, [JSON.stringify(subFolderObj), JSON.stringify(arg)], {
                  env,
                  stdio: ['ipc', out, err]
})

Make sure that you are not using any electron functionality in child process