我目前正在尝试使用 ElectronJS 围绕Microsoft 的 PortQry CLI构建一个包装器,以自动检查与我公司服务(Active Directory、Outlook 等)的连接,并拥有更好看的 GUI。(我喜欢引导)
计划是让我的 electronJS 应用程序在本地运行 CLI 并获取输出。我尝试使用node-cmd但无法显示输出。
以下是我的 electronJS 文件:
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
<p id="input">Hello World</p>
</div>
<script src="./backend.js"></script>
</body>
</html>
后端.js
var cmd=require('node-cmd');
cmd.get(
'C:\PortQryV2\portqry -n google.com -p tcp -o 8080',
function(err, data, stderr){
document.getElementById("input").innerHTML=data;
}
);
main.js
const { app, BrowserWindow } = require('electron')
function createWindow () {
// Create the browser window.
let win = new BrowserWindow({ width: 800, height: 600 })
// and load the index.html of the app.
win.loadFile('index.html')
win.webContents.openDevTools()
}
app.on('ready', createWindow)
所以 PortQry 应该运行,并更改 p 标签以显示输出。但我无法让它工作。我正在考虑看看 nodejs 的 child_process 是否可以工作,但我似乎无法将它导入我的代码中。
任何帮助将不胜感激!