@@ -43,10 +43,23 @@ class CgiRunner implements ExerciseRunnerInterface
4343 */
4444 public function __construct (CgiExercise $ exercise , EventDispatcher $ eventDispatcher )
4545 {
46- // Suppress shell output. Anything non-zero is a failure.
47- @system ('php-cgi --version > /dev/null 2>&1 ' , $ failedToRun );
48- if ($ failedToRun ) {
49- die ('Could not load php-cgi binary. Please install php-cgi using your package manager. ' . PHP_EOL );
46+ if (strpos (PHP_OS , 'WIN ' ) !== false ) {
47+ // Check if in path. 2> nul > nul equivalent to 2>&1 /dev/null
48+ $ silence = (PHP_OS == 'CYGWIN ' ? '> /dev/null 2>&1 ' : '2> nul > nul ' );
49+ system (sprintf ('php-cgi --version %s ' , $ silence ), $ failedToRun );
50+ if ($ failedToRun ) {
51+ $ newPath = realpath (sprintf ('%s/%s ' , dirname (PHP_BINARY ), 'php-cgi.exe ' ));
52+ // Try one more time, relying on being in the php binary's directory (where it should be on Windows)
53+ system (sprintf ('%s --version %s ' , $ newPath , $ silence ), $ stillFailedToRun );
54+ if ($ stillFailedToRun ) {
55+ throw new \RuntimeException ('Could not load php-cgi binary. Please install php-cgi using your package manager. ' );
56+ }
57+ }
58+ } else {
59+ @system ('php-cgi --version > /dev/null 2>&1 ' , $ failedToRun );
60+ if ($ failedToRun ) {
61+ throw new \RuntimeException ('Could not load php-cgi binary. Please install php-cgi using your package manager. ' );
62+ }
5063 }
5164 $ this ->eventDispatcher = $ eventDispatcher ;
5265 $ this ->exercise = $ exercise ;
0 commit comments