diff --git a/app/Services/VsphereHostSshService.php b/app/Services/VsphereHostSshService.php index 8ae1841..4c8eb1e 100644 --- a/app/Services/VsphereHostSshService.php +++ b/app/Services/VsphereHostSshService.php @@ -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; } /**