@@ -247,7 +247,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
247247 $ matches = $ autocomplete ($ ret );
248248 $ numMatches = \count ($ matches );
249249
250- $ sttyMode = shell_exec ( ' stty -g ' );
250+ $ sttyMode = Terminal:: backupSttyMode ( );
251251
<
10BC0
/code>252252 // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
253253 shell_exec ('stty -icanon -echo ' );
@@ -257,11 +257,17 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
257257
258258 // Read a keypress
259259 while (!feof ($ inputStream )) {
260+ do {
261+ // Give signal handlers a chance to run
262+ $ r = [$ inputStream ];
263+ $ w = [];
264+ } while (0 === @stream_select ($ r , $ w , $ w , 0 , 100 ));
265+
260266 $ c = fread ($ inputStream , 1 );
261267
262268 // as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
263269 if (false === $ c || ('' === $ ret && '' === $ c && null === $ question ->getDefault ())) {
264- shell_exec ( sprintf ( ' stty %s ' , $ sttyMode) );
270+ Terminal:: restoreSttyMode ( $ sttyMode );
265271 throw new MissingInputException ('Aborted. ' );
266272 } elseif ("\177" === $ c ) { // Backspace Character
267273 if (0 === $ numMatches && 0 !== $ i ) {
@@ -365,8 +371,7 @@ function ($match) use ($ret) {
365371 }
366372 }
367373
368- // Reset stty so it behaves normally again
369- shell_exec (sprintf ('stty %s ' , $ sttyMode ));
374+ Terminal::restoreSttyMode ($ sttyMode );
370375
371376 return $ fullChoice ;
372377 }
@@ -418,7 +423,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
418423 }
419424
420425 if (self ::$ stty && Terminal::hasSttyAvailable ()) {
421- $ sttyMode = shell_exec ( ' stty -g ' );
426+ $ sttyMode = Terminal:: backupSttyMode ( );
422427 shell_exec ('stty -echo ' );
423428 } elseif ($ this ->isInteractiveInput ($ inputStream )) {
424429 throw new RuntimeException ('Unable to hide the response. ' );
@@ -427,7 +432,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
427432 $ value = fgets ($ inputStream , 4096 );
428433
429434 if (self ::$ stty && Terminal::hasSttyAvailable ()) {
430- shell_exec ( sprintf ( ' stty %s ' , $ sttyMode) );
435+ Terminal:: restoreSttyMode ( $ sttyMode );
431436 }
432437
433438 if (false === $ value ) {
0 commit comments