簡體   English   中英

NodeJS:在Windows 10上的Linux Bash中檢查Machines OS

[英]NodeJS: Check Machines OS while in Linux Bash on Windows 10

我需要根據操作系統執行二進制文件。

我的機器是帶有Ubuntu子系統的Windows 10系統。 當我嘗試使用process.platform獲取操作系統時,控制台會告訴我我正在使用Linux。

我有Windows和Linux的二進制文件,如果當前計算機是Windows,我想運行.exe,但是當process.plattform返回Linux時如何獲得操作系統?

有一個模塊,提供了許多特定於操作系統的實用程序方法。

在Windows 10中,我的代碼是:

var os = require('os');

console.log(os.type()); 
console.log(os.release()); 
console.log(os.platform());

這是我的解決方案:

let OS = os.release();
if(OS.indexOf("Microsoft")>=0){
    bin = bin.concat(".exe");
}

謝謝javatar。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM