automation-stack / electron-sudo

Electron subprocesses with administrative privileges, prompting the user with an OS dialog if necessary.
MIT License
382 stars 55 forks source link

Passing the result of `fs.stat` to `child_process.spawn` #53

Open eriklarko opened 7 years ago

eriklarko commented 7 years ago

When I run the example in the README (without await) I get the following output:

/bin/sh: 1: [object: not found

  The code in its entirety is:

import ElectronSudo from 'electron-sudo';

const options = {
  name: 'YOLO'
};
const sudo = new ElectronSudo(options);

let p = sudo.spawn(
  'echo', ['$PARAM'], {env: {PARAM: 'VALUE'}}
).then( () => {
  p.on('close', () => {
    console.log('stderr:', p.output.stderr.toString());
  });
});

 

After poking around a little in the source code I found that the getBinary method of SudoerLinux returns the result from stat in src/lib/utils.js which is an fs.Stats object. This object is then passed directly to child_process.spawn which would explain the [object part of the error output.

Changing the getBinary method to return the path to the binary instead of the stat object seemed to fix it for me.

Am I using the library wrong?

eriklarko commented 7 years ago

Ah, I did not see https://github.com/automation-stack/electron-sudo/pull/41 :) I'll patch that in then