【问题标题】:Powershell operating system architecture vs NodeJs process.archPowershell 操作系统架构 vs NodeJs process.arch
【发布时间】:2021-08-12 22:17:23
【问题描述】:

我正在使用一个 NodeJs 应用程序,它在内部调用 process.arch 来获取系统架构,然后根据结果构建路径,例如。 - path/to/file/x64/file(应用是 selenium-standalone NPM 包)。

现在我需要在 PowerShell 脚本中构建相同的路径,因此我还需要获取系统架构。但是用 f.ex 来做这件事。 (Get-WmiObject Win32_Processor).AddressWidth 返回没有 x 的结果 - 只是 64 所以我的路径最终是 path/to/file/64/file 这是错误的。我目前的解决方法是显式添加x:

$arch = (Get-WmiObject Win32_Processor).AddressWidth
if ($arch -eq 32) { $arch = 'x32' } 
if ($arch -eq 64) { $arch = 'x64' } 

您认为这样做安全吗?或者有没有办法从 powerShell 获得它已经分配了x

【问题讨论】:

  • 这当然不安全,因为 1) 它假设只有 1 个 Win32_Process 实例存在,并且 2) 它只评估 platform 架构,而不是流程架构。

标签: node.js powershell architecture


【解决方案1】:

process.arch 描述了当前进程的位数(或字宽,或架构或任何你想称呼的) - 因为完全可以在 64 位操作系统上运行 32 位(甚至 16 位)进程。

要确定正在运行的 PowerShell 进程是 32 位还是 64 位(无论操作系统架构如何),请使用 [Environment]::Is64BitProcess

$arch = if([Environment]::Is64BitProcess) { 'x64' } else { 'x32' }

【讨论】:

  • 做得很好。那些对补充问题感兴趣的人 - OS 是 64 位的,与当前进程的位数无关吗? - 可以使用[Environment]::Is64BitOperatingSystem
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-05
  • 1970-01-01
  • 2018-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多