我试图通过SSH在对象中执行查询的结果来解析并显示在网站中。到目前为止,我已经能够执行查询,在控制台日志中我可以看到表输出。下面是我在节点JS中使用的代码片段。这是一个带电子框架的应用程序构建。
我正在从我的客户ssh.executeCommands(['mysql -uroot -prtdb -e "select * from tableName"'], onSuccessCallback, onErrorCallback)
executeCommands函数是
executeCommands(commands, onSuccessCallback, onErrorCallback) {
const onSuccess = data => {
if (onSuccessCallback)
onSuccessCallback(data);
};
const onError = () => {
if (onErrorCallback)
onErrorCallback();
};
let client = new Client();
client.on('ready', () => {
console.log('Connection :: ready');
client.shell((err, stream) => {
if (err) onError();
stream.on('close', () => {
console.log('Stream :: close');
client.end();
onSuccess();
}).on('data', (data) => {
onSuccess(data);
console.log('data: ' + data);
}).stderr.on('data', data => {
console.log('STDERR: ' + data);
onError();
});
});
});
client.on('error', () => {
client.end();
onError();
}
);
this.initClient(client);
}
的控制台日志