Javascript 如何从主流程代码中获取电子标准件内容?
我可以从我的主进程代码中,从Electron获得标准输出的内容吗 例如,我有一个electron应用程序,在我的主要流程代码中:Javascript 如何从主流程代码中获取电子标准件内容?,javascript,google-chrome,electron,Javascript,Google Chrome,Electron,我可以从我的主进程代码中,从Electron获得标准输出的内容吗 例如,我有一个electron应用程序,在我的主要流程代码中: 从“electron”导入{app,BrowserWindow,globalShortcut,session} //现在怎么办?我如何获得任何和所有输出到控制台? 我好奇的原因是,当我使用app.commandLine.appendSwitch(…)为Chrome设置一些标志时,我在控制台中看到Chrome的输出,我想看看是否有可能从我的Electron主进程代码中
从“electron”导入{app,BrowserWindow,globalShortcut,session}
//现在怎么办?我如何获得任何和所有输出到控制台?
我好奇的原因是,当我使用app.commandLine.appendSwitch(…)
为Chrome设置一些标志时,我在控制台中看到Chrome的输出,我想看看是否有可能从我的Electron主进程代码中以某种方式获得此输出
编辑,以防上述内容不够清楚:
电子输出到控制台。我的代码正在运行。例如,底层Chrome实例将信息输出到stdout,因此我自己的electron应用程序将与底层Chrome输出相同的内容输出到stdout
我想使用我自己的electron应用程序中的代码捕获我自己的electron应用程序中的所有put
这有意义吗
例如,如果我在我的Electron主流程代码中添加以下内容:
app.commandLine.appendSwitch('remote-debug-port','8315')
这导致我的Electron应用程序将内容输出到stdout(或类似内容,正如我在终端输出中看到的)
我想从导致输出的相同代码中捕获此输出,因此:
//此行间接导致我的应用程序输出到stdout
//(因为它正在转发Chrome的输出或其他内容):
app.commandLine.appendSwitch('remote-debug-port','8315')
//现在,我如何捕获该输出?
是!你当然可以。只要您的安全允许,Electron与您运行它的机器在本地工作
const buffer_size = (1024 * 500000);//Very large buffer size. Shouldn't ever need anything this big
getCommandLineResponse: async function (callback) {
let date = moment().toDate();
let promise = function () {
return new Promise((resolve, reject) => {
//create a child process to run
var {exec} = require('child_process');
let path = require('path');
let app = require('electron').remote;
let exePath = "YOUREXE.exe";
//Define the command line interface and all arguments
let cli = `"${exePath}"`;
//This is the core. Call the .EXE specifying the options
exec(cli, {maxBuffer: buffer_size}, (err, stdout, stderr) => {
if (err) {
reject(stderr);
} else {
console.log('Received from CLI - ' + stdout);
resolve(stdout);
}
exec = null;
});
});
};
//Execute the CLI
await promise(filePath);
if(callback)
{
await callback();
}
}
我没有弄清楚如何获取标准输出,但我确实弄清楚了如何在Hi Jacob找到调试器websocket URL,谢谢您的回答!我认为我没有很好地解释我的意思,所以我更新了问题。