我正在尝试使用mysqldump创建应用程序的mysql备份。生成子进程似乎无法写入密码。这些都是我迄今为止尝试过的东西。
var spawn = require('child_process').spawn("mysqldump",
["-u", "Username",
"DBName",
">", "./Backup/DB_Backup.sql",
"-p", "Password"]);
spawn.stdin.write("P");
spawn.stdin.write("a");
spawn.stdin.write("s");
spawn.stdin.write("s");
spawn.stdin.write("w");
spawn.stdin.write("o");
spawn.stdin.write("r");
spawn.stdin.write("d");
spawn.stdin.write("\n");
spawn.stdin.write("Password\n");
spawn.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
spawn.stdin.write("Password\n");
});
spawn.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
spawn.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
这个问题看起来像是重复的,但没有一个答案对我有帮助。
2条答案
按热度按时间nnsrf1az1#
替换
"-p", "Password"
在"-pPassword"
例子:30byixjq2#
最好的方法是: