-
-
Save deepak1556/eefed2d47fada30c15ab9077d1532d0b to your computer and use it in GitHub Desktop.
Console windows via spawn calls from ELECTRON_RUN_AS_NODE processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require('child_process') | |
ls = spawn('C:\\Program Files (x86)\\Git\\cmd\\git.exe', ['status'], { | |
cwd: 'C:\\Users\\demohan\\github\\vscode' | |
}) | |
ls.stdout.on('data', (data) => { | |
console.log('stdout : ' + data) | |
}) | |
ls.stderr.on('data', (data) => { | |
console.log('stderr : ' + data) | |
}) | |
ls.on('close', (code) => { | |
console.log('child process exited with code : ' + code) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modules to control application life and create native browser window | |
const {app, BrowserWindow} = require('electron') | |
const path = require('path') | |
const { fork } = require('child_process') | |
let child; | |
function createWindow () { | |
// Create the browser window. | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600 | |
}) | |
// and load the index.html of the app. | |
mainWindow.loadURL('about:blank') | |
mainWindow.webContents.on('did-finish-load', () => { | |
child = fork(`${__dirname}/child.js`) | |
child.on('close', () => { | |
console.log('forked process exited') | |
}) | |
}) | |
} | |
// This method will be called when Electron has finished | |
// initialization and is ready to create browser windows. | |
// Some APIs can only be used after this event occurs. | |
app.whenReady().then(() => { | |
createWindow() | |
app.on('activate', function () { | |
// On macOS it's common to re-create a window in the app when the | |
// dock icon is clicked and there are no other windows open. | |
if (BrowserWindow.getAllWindows().length === 0) createWindow() | |
}) | |
}) | |
// Quit when all windows are closed, except on macOS. There, it's common | |
// for applications and their menu bar to stay active until the user quits | |
// explicitly with Cmd + Q. | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') app.quit() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment