Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要筛选systeminfo findstr_Javascript_Html_Shell_Electron - Fatal编程技术网

Javascript 需要筛选systeminfo findstr

Javascript 需要筛选systeminfo findstr,javascript,html,shell,electron,Javascript,Html,Shell,Electron,我正试图在一个电子桌面应用程序中呈现用户和计算机信息,到目前为止,它看起来不错。但是,我需要通过过滤掉systeminfo | findstr的“键”并只显示“值”来细化它。 如果我在.js文件中运行这一行:让winOSName=shell.exec('systeminfo | findstr/C:'OS Name'),我会得到:OS Name:Microsoft Windows 10 Pro,键和值之间有大量空格。有没有办法过滤掉这里的“操作系统名称” My.js代码: const shell

我正试图在一个电子桌面应用程序中呈现用户和计算机信息,到目前为止,它看起来不错。但是,我需要通过过滤掉
systeminfo | findstr
的“键”并只显示“值”来细化它。 如果我在.js文件中运行这一行:
让winOSName=shell.exec('systeminfo | findstr/C:'OS Name')
,我会得到:OS Name:Microsoft Windows 10 Pro,键和值之间有大量空格。有没有办法过滤掉这里的“操作系统名称”

My.js代码:

const shell = require('shelljs')
let path = require('path')

shell.config.execPath = path.join('C:', 'Program Files', 'nodejs', 'node.exe')

function getData () {
// For Windows
  let winComputerName = shell.exec('hostname')
  let winUserName = shell.exec('whoami')
  // let winOS = shell.exec('ver')
  let winOSVersion = shell.exec('systeminfo | findstr /C:"OS Name"')
  let winOSOwner = shell.exec('systeminfo | findstr /C:"Registered Owner"')

  let computerNameTextField = document.querySelector('#computerName')
  let userNameTextField = document.querySelector('#userName')
  let osNameTextField = document.querySelector('#osName')
  let userEmailTextField = document.querySelector('#userEmail')

  computerNameTextField.setAttribute('value', winComputerName)
  userNameTextField.setAttribute('value', winUserName)
  osNameTextField.setAttribute('value', winOSVersion)
  userEmailTextField.setAttribute('value', winOSOwner)
}
我的HTML:

<div class="formHolder">
  <form>
    Computer Name:
    <input type="text" name="computerName" id="computerName"><br>
    User:
    <input type="text" name="userName" id="userName"><br>
    OS:
    <input type="text" name="osName" id="osName"><br>
    User Email:
    <input type="text" name="osName" id="userEmail"><br>
  </form>
</div>

计算机名:

用户:
操作系统:
用户电子邮件:

我通过使用.substring(x,x)来管理它。我希望它也能在其他机器上工作。
让winOSOwner=shell.exec('systeminfo | findstr/C:“注册所有者”)
让userEmailTextField=document.querySelector(“#userEmail”)
userEmailTextField.setAttribute('value',winOSOwner.substring(27,48))

最好使用node.js来获取系统信息。您的方法将在linux/osx中失败