Skip to content

Commit

Permalink
update batch execute return value
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonewu committed Dec 18, 2022
1 parent c89275a commit e7e078d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const batchRes = await sshTunnel.batchExec([
'echo 2',
'echo 3'
]);
// batchRes: [1, 2, 3]
// batchRes: [{ command: 'echo 1', result: '1' }, { command: 'echo 2', result: '2' }, { command: 'echo 3', result: '3' }]
// forward local port 3000 to 192.168.1.1:3000
const proxyRes = sshTunnel.proxy('3000:192.168.1.1:3000');
// forward multiple port to specific servers
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "ssh-tunneling",
"version": "1.0.6",
"version": "1.0.7",
"description": "a ssh-tunneling client for nodejs",
"keywords": ["ssh tunnel", "ssh tunneling", "ssh proxy", "ssh port foward"],
"main": "dist/index.js",
Expand Down
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,18 @@ class SshTunnel {
/**
* execute multiple commands
* @params an array of commands
* @return an result array of every command
* @return return an executed result array of every command by original order
*/
public batchExec = async (commands: string[]) => {
const divider = '__ssh_tunneling_divider__'
const command = commands.join(` && echo ${divider} && `);
const res = await this.exec(command);
return res.split(`${divider}\n`);
const combinedCommand = commands.join(` && echo ${divider} && `);
const res = (await this.exec(combinedCommand)).split(`${divider}\n`);
return commands.map((command, i) => {
return {
command,
result: res[i]
}
});
}

}
Expand Down

0 comments on commit e7e078d

Please sign in to comment.