michauwilliam michauwilliam - 4 months ago 51
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:

#!/usr/bin/bash
mysql


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});
child.unref();


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!

Answer

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

Comments