Skip to content

Commit

Permalink
fix windows with newest symfony/process
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemorroj committed Dec 31, 2019
1 parent 513b4ad commit 171d5d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"ext-pcre": "*",
"ext-mbstring": "*",
"ext-json": "*",
"symfony/process": "^4.0|^5.0"
"symfony/process": "^4.2|^5.0"

},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan": "^0.12",
"friendsofphp/php-cs-fixer": "^2.16"
},
"autoload": {
Expand Down
24 changes: 6 additions & 18 deletions src/OS/Windows.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Ginfo\OS;

use Ginfo\Exceptions\FatalException;
use Ginfo\Info\Cpu;
use Ginfo\Info\Disk\Drive;
use Ginfo\Info\Disk\Mount;
Expand All @@ -24,25 +23,14 @@
*/
class Windows extends OS
{
private $process;
private $infoCache = [];
private $powershellDirectory;

/**
* Windows constructor.
*
* @throws FatalException
*/
public function __construct()
{
try {
$powershellDirectory = \getenv('SystemRoot').'\\System32\\WindowsPowerShell\\v1.0';
if (!\is_dir($powershellDirectory)) {
$powershellDirectory = null;
}

$this->process = new SymfonyProcess(null, $powershellDirectory);
} catch (\Exception $e) {
throw new FatalException($e->getMessage());
$this->powershellDirectory = \getenv('SystemRoot').'\\System32\\WindowsPowerShell\\v1.0';
if (!\is_dir($this->powershellDirectory)) {
$this->powershellDirectory = null;
}
}

Expand All @@ -52,8 +40,8 @@ private function getInfo(string $name): ?array
return $this->infoCache[$name];
}

$process = $this->process->setCommandLine('chcp 65001 | powershell -file '.__DIR__.'/../../bin/windows/'.$name.'.ps1');
$process->run();
$process = SymfonyProcess::fromShellCommandline('chcp 65001 | powershell -file "!FILE!"', $this->powershellDirectory);
$process->run(null, ['FILE' => __DIR__.'/../../bin/windows/'.$name.'.ps1']);

if (!$process->isSuccessful()) {
return null;
Expand Down

0 comments on commit 171d5d8

Please sign in to comment.