Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proper use of ps.dispose #137

Open
ghost opened this issue Aug 14, 2021 · 1 comment
Open

proper use of ps.dispose #137

ghost opened this issue Aug 14, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 14, 2021

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
Copy link

slobo80 commented Aug 25, 2021

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();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant