You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error when executing command with streaming stdout/stderr callbacks #257
Hi @Ajay-MS, sorry this sat for so long. The second argument of exec() is the list of parameters to escape, and options go third. Your snippet passed the options object as the parameters, which shell-escape then tried to iterate. Since v9, exec() checks its arguments, so this now rejects with AssertionError: parameters must be a valid array instead of a.forEach is not a function. Use either:
awaitssh.exec(command,[],{ onStdout, onStderr })// command plus escaped parametersawaitssh.execCommand(command,{ onStdout, onStderr })// command is already a full string
On the throw inside onStderr: in v14, if onStdout, onStderr or onChannel throws, the promise from exec/execCommand rejects with that error, and only that command's channel is closed. Before, the exception escaped into ssh2, which treated it as a connection error, closed the connection and crashed the process. If you only want to fail when the command writes to stderr, you don't need to throw. exec() with the default stream: 'stdout' already rejects with the stderr text, and execCommand() returns stderr and code for you to check.
Activity
steelbrain commentedon Feb 6, 2020
Hi @Ajay-MS
What's the value of
commandToExecutehere? You may want to useexecCommandinstead ofexechere.steelbrain commentedon Nov 16, 2026
Hi @Ajay-MS, sorry this sat for so long. The second argument of
exec()is the list of parameters to escape, and options go third. Your snippet passed the options object as the parameters, which shell-escape then tried to iterate. Since v9,exec()checks its arguments, so this now rejects withAssertionError: parameters must be a valid arrayinstead ofa.forEach is not a function. Use either:On the
throwinsideonStderr: in v14, ifonStdout,onStderroronChannelthrows, the promise fromexec/execCommandrejects with that error, and only that command's channel is closed. Before, the exception escaped into ssh2, which treated it as a connection error, closed the connection and crashed the process. If you only want to fail when the command writes to stderr, you don't need to throw.exec()with the defaultstream: 'stdout'already rejects with the stderr text, andexecCommand()returnsstderrandcodefor you to check.Reject exec on connection errors and throwing callbacks (#132, #257)