michauwilliam michauwilliam - 11 months ago 182
MySQL Question

Spawn interactive process and exit in NodeJS

I'm trying to accomplish (I think) a fairly simple thing, but couldn't find any existing answers, so here it goes.

I would like to imitate the following bash script in node:


so basically exactly like typing 'mysql' in the command line. So far I came up with the following:

var spawn = require('child_process').spawn;
var child = spawn('/usr/bin/mysql', [], {stdio: 'inherit', detached: true});

which works ok (presents me with the mysql prompt), but when I type a command it gets sent to the bash command line not the mysql.
I've tried other stdio options (pipe, ignore) with listeners on stdout, stderr etc, but this got me as far as hanging empty prompt. Any and all suggestions appreciated!


Have you tried without detached: true? It should work with stdio set to inherit and detached not set in the options