如何通过child_process程序开始电子应用?

时间:2019-06-17 09:46:04

标签: node.js electron child-process

我需要以编程方式启动electron.js应用程序。以下使用execa库的解决方案有效,但是我没有找到答案,如何使控制台在console.log()here is that question)内显示InitializeProject_GUI.js

import executeExternalCommand, { ExecaReturnValue } from 'execa';

const executionResult: ExecaReturnValue<string> = await executeExternalCommand(
    'electron',
    ['InitializeProject_GUI.js'],
    { cwd: __dirname }
);

因此,我决定改用标准child_process。也许会更容易找到如何显示console.log()的子过程,但是首先我需要开始进行电子应用。

import ChildProcess, { ChildProcess as ChildProcess__type } from 'child_process';

const childProcess: ChildProcess__type = ChildProcess.spawn(
    'electron',
    ['InitializeProject_GUI.js'],
    { cwd: __dirname }
);

我得到了Error: spawn electron ENOENT

enter image description here

此外,ChildProcess.exec('electron InitializeProject_GUI.js', { cwd: __dirname });也不执行。

而且,ChildProcess.execSync('electron InitializeProject_GUI.js', { cwd: __dirname });导致错误的编码错误:

enter image description here

0 个答案:

没有答案