Skip to content

Commit ab8e0cd

Browse files
committed
Refactoring, and change to return trimmed output and error by default
1 parent 98ef0db commit ab8e0cd

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/SSHCommand.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ private function execute()
3636
throw new RuntimeException('Failed to execute command (no stdout stream): '.$this->command);
3737
}
3838

39+
$this->readStreams($stdout, $stderr);
40+
}
41+
42+
private function readStreams($stdout, $stderr)
43+
{
3944
$startTime = time();
4045

4146
do {
42-
$this->error = fread($stderr, self::STREAM_BYTES_PER_READ);
4347
$this->output = fread($stdout, self::STREAM_BYTES_PER_READ);
48+
$this->error = fread($stderr, self::STREAM_BYTES_PER_READ);
4449

45-
$streamsComplete = (feof($stderr) && feof($stdout));
50+
$streamsComplete = (feof($stdout) && feof($stderr));
4651

4752
if (!$streamsComplete) {
4853
// Prevent thrashing.
@@ -54,13 +59,23 @@ private function execute()
5459
} while ($executionDuration <= self::EXECUTION_TIMEOUT_SECONDS && !$streamsComplete);
5560
}
5661

57-
public function getOutput(): string
62+
public function getRawOutput(): string
5863
{
5964
return $this->output;
6065
}
6166

62-
public function getError(): string
67+
public function getRawError(): string
6368
{
6469
return $this->error;
6570
}
71+
72+
public function getOutput(): string
73+
{
74+
return trim($this->getRawOutput());
75+
}
76+
77+
public function getError(): string
78+
{
79+
return trim($this->getRawError());
80+
}
6681
}

0 commit comments

Comments
 (0)