Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
shelladapter.php
1<?php
2namespace Bitrix\Scale;
3
10{
11 const SUCCESS_RESULT = 0;
12
13 protected $resOutput = "";
14 protected $resError = "";
15
22 protected function prepareExecution($command)
23 {
24 if($command == '')
25 throw new \Bitrix\Main\ArgumentNullException("command");
26
27 $this->resOutput = "";
28 $this->resError = "";
29
30 return escapeshellcmd($command);
31 }
32
39 public function asyncExec($command)
40 {
41 $outputPath = "/dev/null";
42 $command = $this->prepareExecution($command);
43 exec($command. " > ".$outputPath." 2>&1 &");
44 return true;
45 }
46
50 public function getLastOutput()
51 {
52 return $this->resOutput;
53 }
54
58 public function getLastError()
59 {
60 return $this->resError;
61 }
62
68 public function syncExec($command)
69 {
70 $command = $this->prepareExecution($command);
71 $retVal = 1;
72
73 $descriptorspec = array(
74 0 => array("pipe", "r"), // stdin
75 1 => array("pipe", "w"), // stdout
76 2 => array("pipe", "w") // stderr
77 );
78
79 $pipes = array();
80 $process = proc_open('/bin/bash', $descriptorspec, $pipes);
81
82 if (is_resource($process))
83 {
84 fwrite($pipes[0], $command);
85 fclose($pipes[0]);
86
87 $this->resOutput = stream_get_contents($pipes[1]);
88 fclose($pipes[1]);
89
90 $this->resError = stream_get_contents($pipes[2]);
91 fclose($pipes[2]);
92
93 $retVal = proc_close($process);
94 }
95
96 return $retVal == static::SUCCESS_RESULT;
97 }
98}