SunilWang / node-os-utils

OS Utils - An operating system utility library.
https://www.npmjs.com/package/node-os-utils
MIT License
126 stars 19 forks source link

osu.drive dont works on Windows #26

Open SrRapero720 opened 3 years ago

SrRapero720 commented 3 years ago

My english is so bad, so I may sound incoherent or rude. So I'll get right to the point. i see in the in drive.js you are using df -kP. its a great commant for linux users (and servers) but when you try to run that on Windows console and the spam are inevitable image

I check on forums and test by myself and i found the "equivalent" of df -kP and is get-psdrive –psprovider filesystem. Actually the command give you the Free Mem, Used Mem and Root, (not root or Administrator permission required)

well its posible to get compatibilty. just add a conditional for windows like this (or someting like this) https://github.com/SunilWang/node-os-utils/blob/4136218f8cc79d84974d759bd70b0f067c3790f8/lib/drive.js#L38-L43

//required 'os' dependency
  info: function (diskName) {
    if (!diskName) {
      diskName = '/'
    }
    if (os.version().toLowerCase().includes('windows')) return exec('get-psdrive –psprovider filesystem', (out) => {})
    else (os.version().toLowerCase().includes('linux')) return exec('df -kP', (out) => {}) {}

i hope you have planed to add windows support on osu.drive. is very strange found good libraries with this feature.

RafeSafari commented 3 years ago

I have the same problem. In addition wrong error will be thrown! Just add a line at drive.js:44 to check out variable and throw related error. Using this npm module was a waste of time. At least add a list of supported operating systems!

SrRapero720 commented 2 years ago

Update about this I found better documentation about this and possible alternatives (excluding my suggestions).

  1. Get-CimInstance -ClassName Win32_LogicalDisk get all devices. letter, size and free space (in bytes)
  2. Get-Volume Its less easy to parse and space are converted in GB/MB. but give more info like FileSystem, Health and Operational status

In addition of that. these commands only works on Powershell and exec still use CMD (idk why) but can be used replacing EXEC with SPAWN

var spawn = require("child_process").spawn,child;
child = spawn("powershell.exe",["c:\\temp\\helloworld.ps1"]);
child.stdout.on("data",function(data){
    console.log("Powershell Data: " + data);
});
child.stderr.on("data",function(data){
    console.log("Powershell Errors: " + data);
});
child.on("exit",function(){
    console.log("Powershell Script finished");
});
child.stdin.end(); //end input