I want to create a dump file from the folowing select in nodeJS:
SELECT o1.* FROM objects_pool o1 inner join objects_pool o2 on o1.op_id = o2.op_id_object_corpse where o2.op_id_zone_pool = 41
I tried:
exec( 'mysql -e "SELECT o1.* FROM objects_pool o1 inner join objects_pool o2 on o1.op_id = o2.op_id_object_corpse where o2.op_id_zone_pool = 41" -u root -pxxxxx dbNAME > FILE_PATH'
but the only thing I get is a list of results.
You cannot use pipes or redirects from within child_process.exec
. If you want to specifiy a different output for child_process.exec
than stdout, you will have to do it by spcifiying it in the options (also see the documentation):
var fileOut = fs.createWriteStream('FILE_PATH');
child_process.exec('mysql -e "SELECT o1.* FROM objects_pool o1 inner join objects_pool o2 on o1.op_id = o2.op_id_object_corpse where o2.op_id_zone_pool = 41" -u root -pxxxxx dbNAME', {stdio: [undefined, fileOut, undefined]}, function (err) {
// called when done
fileOut.end();
});