Skip to content

Instantly share code, notes, and snippets.

@RealYukiSan
Created April 11, 2024 07:21
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 RealYukiSan/e236f2798d5df04ed2dfbef35681a2e2 to your computer and use it in GitHub Desktop.
Save RealYukiSan/e236f2798d5df04ed2dfbef35681a2e2 to your computer and use it in GitHub Desktop.
use sh inside javascript
const { spawn } = require('node:child_process')
const readline = require('node:readline');
const { stdin: input, stdout: output } = require('node:process');
const rl = readline.createInterface({ input, output });
const shell = spawn('sh')
shell.stdout.on('data', (data) => {
process.stdout.write(data.toString())
init()
});
function init() {
rl.question('Enter command > ', (cmd) => {
if (cmd == 'quit') {
rl.close();
shell.kill();
}
else {
shell.stdin.write(`${cmd}\n`);
}
});
}
init()
@RealYukiSan
Copy link
Author

read the docs:

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