@@ -19,16 +19,14 @@ class Shell {
19
19
protected $ cwd ;
20
20
protected $ descriptors ;
21
21
protected $ env ;
22
- protected $ error ;
23
22
protected $ input ;
24
- protected $ output ;
25
23
protected $ pipes ;
26
24
protected $ process ;
27
25
protected $ startTime ;
28
26
protected $ status ;
29
27
protected $ timeout ;
30
28
31
- public function __construct ($ command , $ cwd = null , $ input = null , $ env = null , $ timeout = 60 )
29
+ public function __construct (string $ command , string $ cwd = null , string $ input = null , string $ env = null , float $ timeout = 60 )
32
30
{
33
31
if (!\function_exists ('proc_open ' )) {
34
32
throw new RuntimeException ('Required proc_open could not be found in your PHP setup ' );
@@ -39,6 +37,7 @@ public function __construct($command, $cwd = null, $input = null, $env = null, $
39
37
$ this ->env = $ env ;
40
38
$ this ->input = $ input ;
41
39
$ this ->timeout = $ timeout ;
40
+ $ this ->status = null ;
42
41
}
43
42
44
43
private function getDescriptors ()
@@ -84,9 +83,9 @@ public function execute(bool $blocking = false)
84
83
}
85
84
86
85
$ this ->setInput ();
86
+ $ this ->updateStatus ();
87
87
88
88
$ this ->startTime = microtime (true );
89
- $ this ->status = $ this ->updateStatus ();
90
89
91
90
if ($ blocking ) {
92
91
$ this ->wait ();
@@ -95,16 +94,12 @@ public function execute(bool $blocking = false)
95
94
96
95
public function getOutput ()
97
96
{
98
- $ this ->output = stream_get_contents ($ this ->pipes [self ::STDOUT_DESCRIPTOR_KEY ]);
99
-
100
- return $ this ->output ;
97
+ return stream_get_contents ($ this ->pipes [self ::STDOUT_DESCRIPTOR_KEY ]);
101
98
}
102
99
103
100
public function getErrorOutput ()
104
101
{
105
- $ this ->error = stream_get_contents ($ this ->pipes [self ::STDERR_DESCRIPTOR_KEY ]);
106
-
107
- return $ this ->error ;
102
+ return stream_get_contents ($ this ->pipes [self ::STDERR_DESCRIPTOR_KEY ]);
108
103
}
109
104
110
105
public function getExitCode ()
@@ -134,7 +129,7 @@ public function wait()
134
129
135
130
public function isRunning ()
136
131
{
137
- return $ this ->status ['running ' ];
132
+ return $ this ->status && $ this -> status ['running ' ];
138
133
}
139
134
140
135
public function stop ()
@@ -144,8 +139,10 @@ public function stop()
144
139
}
145
140
146
141
$ this ->closePipes ();
147
- proc_close ($ this ->process );
148
- $ this ->updateStatus ();
142
+
143
+ if (\is_resource ($ this ->process )) {
144
+ proc_close ($ this ->process );
145
+ }
149
146
150
147
return $ this ->getExitCode ();
151
148
}
0 commit comments