Skip to content

Instantly share code, notes, and snippets.

@Dragod
Last active October 5, 2021 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dragod/a2f21b2968ea82fd7166a7814b94bf1a to your computer and use it in GitHub Desktop.
Save Dragod/a2f21b2968ea82fd7166a7814b94bf1a to your computer and use it in GitHub Desktop.
Catch exexSync errors

If you want to get net wlan show profiles output no matter if it fails or not, you can use either asynchronous version of exec. The callback will have stdout set.

Or you can catch exception and get stdout from there. Something like:

let nestsh_output;
try {
  netsh_output = execSync('netsh wlan show profiles');
} catch (ex) {
  netsh_output = ex.stdout;
}

That said, I don't see any issue with Node.js here, so I will close this. If you think that there is a bug here feel free to reopen the issue. If you have more questions about how to do stuff in Node.js, check out https://github.com/nodejs/help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment