(OS X) Spawn another electron instance from within packaged app


I am using Electron under an OS X environment. In my app, I need at some point to spawn another Electron process, so that it runs as a separate, detached instance of electron on a different script.

Say that I have two apps, parent and child, in two separate folders, with separate package.json and so on. Now, if I run electron parent/ the parent app starts. After a while, the parent decides to spawn another, separate, detached instance of electron to run the child app. It does so by running:

child_process.spawn(process.argv[0], ['/path/to/child'], {detached: true});

This does work! If I run it from the terminal using my electron command, everything works fine, two instances are spawned, they are independent and behave nicely.

Now, I want to package this. To do this, I download the packaged Electron.app and add a the folder Electron.app/Contents/Resources/app. Now, inside the app folder, I am putting my parent app (as it is the one that should be started when my user opens the packaged app).

Now, when parent is running, we will have that process.argv[0] is the Electron.app/Contents/MacOS/Electron. And here comes the problem: when an app folder is set in Electron.app/Contents/Resources, the packaged Electron executable will just ignore any parameter given to it and will run the app inside the app folder. Therefore, when parent tries to spawn child, as a matter of fact just another instance of parent gets spawned.

I have no clue on how to work around this. Am I doing something wrong? Is there any other different approach to this problem?


Why run as a completely separate application? Why not open a second BrowserWindow with whatever you want to be running in the other app?


I have some very specific reasons to do so. I have been thinking about this design for months, and it is really the one that best suits my needs. Is there any way to get the behavior I am looking for?


I’m sure there probably is. I don’t know how to achieve it though. I would probably just start with creating two separate Electron applications and starting the second one like you would any other GUI app.


Hi, did you solve this problem?

I also met the same problem, I want run another app by parent electron app.