1

我想从 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

我试过了:

执行('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'

但我唯一得到的是结果列表。

4

1 回答 1

0

您不能从内部使用管道或重定向child_process.exec。如果您想为child_process.execstdout 指定不同的输出,则必须通过在选项中指定它来执行此操作(另请参阅文档):

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();
});
于 2012-07-06T09:13:55.950 回答