rannn505 / child-shell

Node.js bindings 🔗 for shell
http://rannn505.github.io/child-shell/
MIT License
299 stars 71 forks source link

proper use of ps.dispose #137

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi, anyone knows how to use ps.dispose properly ? As I understood it release resources. As per the example below it release only when there are errors. Shouldn’t we also need to release resources when we successfully invoke scripts? Somewhere I also seen use of process.exit() after ps.dispose(). Any good example of uses of this tool will be great help.

` const shell = require('node-powershell');

let ps = new shell({ executionPolicy: 'Bypass', noProfile: true });

ps.addCommand('echo node-powershell') ps.invoke() .then(output => { console.log(output); //shouldn’t we use ps.dispose() here also?? }) .catch(err => { console.log(err); ps.dispose(); }); `

slobo80 commented 3 years ago

I believe we need to move dispose to finally function: ps.invoke() .then(output => { console.log(output); }) .catch(err => { console.error(err); }) .finally(() => { ps.dispose(); process.exit(); });