Skip to content

Instantly share code, notes, and snippets.

@worldOneo
Created March 17, 2023 09:44
Show Gist options
  • Save worldOneo/5ebde9fb22df1e39a9c5dda0a36896b1 to your computer and use it in GitHub Desktop.
Save worldOneo/5ebde9fb22df1e39a9c5dda0a36896b1 to your computer and use it in GitHub Desktop.
NodeJS simple subprocess shell
const {spawn} = require('child_process');
const child = spawn('/bin/bash');
process.stdin.on('data', function(data) {
child.stdin.write(data);
});
child.stdout.on('data', function(data) {
process.stdout.write(data);
});
child.stderr.on('data', function(data) {
process.stderr.write(data);
});
child.on('exit', function(code) {
process.exit(code);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment