我尝试过不同的方法,我尝试了运行这些命令从SQLite DB生成CSV的shelljs,
shell.exec('sqlite3 /path/to/sqlite-db.db')
shell.exec('.headers on')
shell.exec('.mode csv');
shell.exec('.output /path/to/data.csv');
shell.exec('select * from Table;');
shell.exec('.quit');但是它被第一个命令卡住了,我需要在SQLite cmd中运行所有其他命令。在终端上,这些命令正常工作。
或者还有别的办法可以做到吗?
发布于 2018-05-21 21:20:10
您不需要使用sqlite3 shell,您可以通过Node的内置child_process.exec()-method传递选项。
const exec = require("child_process").exec
const command = 'sqlite3 -header -csv /path/to/sqlite-db.db "select * from Table;" > /path/to/data.csv'
exec(command, (err, stdout, stderr) => {
if (err) return console.error(err)
console.log("stdout: ", stdout)
console.log("stderr: ", stderr)
})https://stackoverflow.com/questions/50456336
复制相似问题