@@ -256,14 +256,11 @@ public function start(callable $callback = null)
256256 if ($ this ->isRunning ()) {
257257 throw new RuntimeException ('Process is already running ' );
258258 }
259- if ($ this ->outputDisabled && null !== $ callback ) {
260- throw new LogicException ('Output has been disabled, enable it to allow the use of a callback. ' );
261- }
262259
263260 $ this ->resetProcessData ();
264261 $ this ->starttime = $ this ->lastOutputTime = microtime (true );
265262 $ this ->callback = $ this ->buildCallback ($ callback );
266- $ descriptors = $ this ->getDescriptors ();
263+ $ descriptors = $ this ->getDescriptors ($ callback );
267264
268265 $ commandline = $ this ->commandline ;
269266
@@ -356,7 +353,12 @@ public function wait(callable $callback = null)
356353 $ this ->requireProcessIsStarted (__FUNCTION__ );
357354
358355 $ this ->updateStatus (false );
356+
359357 if (null !== $ callback ) {
358+ if (!$ this ->processPipes ->haveReadSupport ()) {
359+ $ this ->stop (0 );
360+ throw new \LogicException ('Pass the callback to the Process:start method or enableOutput to use a callback with Process::wait ' );
361+ }
360362 $ this ->callback = $ this ->buildCallback ($ callback );
361363 }
362364
@@ -1181,12 +1183,24 @@ public static function isPtySupported()
11811183 return $ result = (bool ) @proc_open ('echo 1 ' , array (array ('pty ' ), array ('pty ' ), array ('pty ' )), $ pipes );
11821184 }
11831185
1186+ /**
1187+ * Returns whether a callback is used on underlying process output.
1188+ *
1189+ * @internal
1190+ *
1191+ * @return bool
1192+ */
1193+ public function hasCallback ()
1194+ {
1195+ return (bool ) $ this ->callback ;
1196+ }
1197+
11841198 /**
11851199 * Creates the descriptors needed by the proc_open.
11861200 *
11871201 * @return array
11881202 */
1189- private function getDescriptors ()
1203+ private function getDescriptors (callable $ callback = null )
11901204 {
11911205 if ('\\' === DIRECTORY_SEPARATOR ) {
11921206 $ this ->processPipes = WindowsPipes::create ($ this , $ this ->input );
@@ -1207,10 +1221,19 @@ private function getDescriptors()
12071221 *
12081222 * @return \Closure A PHP closure
12091223 */
1210- protected function buildCallback ($ callback )
1224+ protected function buildCallback (callable $ callback = null )
12111225 {
1226+ if ($ this ->outputDisabled ) {
1227+ return function ($ type , $ data ) use ($ callback ) {
1228+ if (null !== $ callback ) {
1229+ call_user_func ($ callback , $ type , $ data );
1230+ }
1231+ };
1232+ }
1233+
12121234 $ out = self ::OUT ;
1213- $ callback = function ($ type , $ data ) use ($ callback , $ out ) {
1235+
1236+ return function ($ type , $ data ) use ($ callback , $ out ) {
12141237 if ($ out == $ type ) {
12151238 $ this ->addOutput ($ data );
12161239 } else {
0 commit comments