SunilWang / node-os-utils

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

executing df command in drive.info() #5

Closed niklas-englert closed 4 years ago

niklas-englert commented 4 years ago

I really enjoy your npm pagage node-os-utils, but I ran into some problems using osu.drive functions. It kept throwing Error: disk name invalid and / not found.
So I did some debugging and found out, that you are using the df -kP command, to gather plain text information about free disk space.
After that you parse that information by using the headline column names and iterating through the rows looking for lines[i]['Mounted on'] === diskName. But this works only if the shell is running in english and df prints out an english headline. Which sadly isn't the case with me (it's german): Screenshot 2019.12.24 22:34:48

For international support I whould like to suggest two possible fixes / updates:

  1. Changing line 43 of /lib/drive.js to

    return exec('LC_ALL="en_US.UTF-8";LANG="en_US.UTF-8";LANGUAGE="en_US:en";df -kP')().then(function(out) {

    which whould set the language of the child process to english, so you can expect df to output a english headline.

  2. Changing line 12 of /lib/exec.js to

      cp.exec('LC_ALL="en_US.UTF-8";LANG="en_US.UTF-8";LANGUAGE="en_US:en";'+command, { shell: true }, function (err, stdout, stderr) {

    which whould set the language of all child processes to english, so you can expect all command outputs to be english as well.

Merry Christmas from Niklas Englert in Germany

(sorry for bad english)

SunilWang commented 4 years ago

@niklas-englert

fix done!

to see: https://www.npmjs.com/package/node-os-utils

$ npm install node-os-utils@1.2.0

You too Merry Christmas.🎄🎅