从select创建转储文件

时间:2012-07-06 09:00:17

标签: mysql node.js

我想从nodeJS中的下面的select中创建一个转储文件:

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

我试过了:

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'

但我唯一得到的是结果清单。

1 个答案:

答案 0 :(得分:0)

您无法在child_process.exec内使用管道或重定向。如果你想为child_process.exec指定一个不同于stdout的输出,你必须通过在选项中添加它来实现它(也参见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();
});