Enhance SSH execution in VsphereHostSshService to capture stdout and stderr; improve error handling for command execution

This commit is contained in:
baodev0
2026-07-13 15:54:31 +07:00
parent 08f65a4ba9
commit 71878b4684
+18 -4
View File
@@ -247,14 +247,28 @@ final class VsphereHostSshService
);
}
$output = $client->exec($remoteCmd);
$stdout = $client->exec($remoteCmd);
$stderr = $client->getStdError();
Log::info('VsphereHostSshService: SSH executed', [
'host' => $config['host'],
'port' => $config['port'],
'host' => $config['host'],
'port' => $config['port'],
'stdout' => trim((string) $stdout),
'stderr' => trim((string) $stderr),
]);
return (string) $output;
if ($stdout === false) {
throw new \RuntimeException(
"SSH exec failed on {$config['host']}:{$config['port']}. stderr: " . trim((string) $stderr)
);
}
// Windows SSH servers sometimes write script output to stderr instead of stdout
if (trim($stdout) === '' && trim((string) $stderr) !== '') {
return (string) $stderr;
}
return (string) $stdout;
}
/**