diff --git a/lib/utils/createSshConnection.js b/lib/utils/createSshConnection.js index 988af8f..135977d 100644 --- a/lib/utils/createSshConnection.js +++ b/lib/utils/createSshConnection.js @@ -149,7 +149,23 @@ export async function createSshConnection({ host, username, port = 22, privateKe interactive, script: (scriptContent, onData) => script(scriptContent, onData, false), sudoScript: (scriptContent, onData) => script(scriptContent, onData, true), - exec: (command, onData) => execRemote(connObj, command, onData, config), + exec: (command, optionsOrOnData, onData) => { + if (typeof optionsOrOnData === 'function') { + onData = optionsOrOnData; + optionsOrOnData = {}; + } + + let envString = ''; + if (optionsOrOnData?.env) { + for (const [key, value] of Object.entries(optionsOrOnData.env)) { + envString += `${key}='${value}' `; + } + } + + const fullCommand = `${envString}${command}`; + + return execRemote(connObj, fullCommand, onData, config); + }, close: () => { return new Promise(resolve => { connObj.once('close', resolve);