我目前正在尝试使用ElectronJS在Microsoft's PortQry CLI周围构建一个包装器,以自动检查与我公司的服务(Active Directory、Outlook等)的连接。并且有一个更好看的GUI。(我喜欢bootstrap)
我的计划是让我的electronJS应用程序在本地运行命令行界面并获得输出。我尝试使用node-cmd,但无法显示输出。
下面是我的electronJS文件:
Index.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>backend.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是否可以工作,但我似乎无法将它导入到我的代码中。
任何帮助都将不胜感激!
发布于 2019-03-20 22:26:43
我现在意识到这个问题有多愚蠢了。
Electronjs使用nodejs作为运行时。我之前在chrome中启动了index.html,因此它从来没有工作过。你必须启动电子应用程序,它才能工作。
https://stackoverflow.com/questions/55222594
复制相似问题