I want to build a tiny script that being run should create a bash-like session (in the current bash session, where the process is created), that can be used later for some mad science (e.g. piping to browser).
I tried using pty.js, piping stdin
to the bash
process, and data from the bash session to the stdout
stream:
var pty = require("pty.js");
var term = pty.spawn('bash', [], {
name: 'xterm-color',
cols: process.stdout.columns,
rows: process.stdout.rows,
cwd: ".",
env: process.env
});
term.pipe(process.stdout);
process.stdin.pipe(term);
term.on("close", function () {
process.exit();
});
This works, but it's very buggy:
For example, the non-characters (directional keys, tab etc) are not caught.
I also tried using spawn
, this not being so bad, but still buggy.
var spawn = require("child_process").spawn;
var bash = spawn("bash");
bash.stdout.pipe(process.stdout);
process.stdin.pipe(bash.stdin);
Is there a better solution how to create a bash wrapper in NodeJS?