Page MenuHomePhabricator

Extension:SyntaxHighlight fail to invoke Pygments.exe on Windows (probably shell exec is broken on Windows)
Closed, DuplicatePublic

Description

Hello,

I've just migrated and upgraded our company's MediaWiki to a new server. Windows Server 2012 R2, Apache 2.4.33 64bit + PHP 7.1.19 64bit + Python 3.6 64bit, MediaWiki 1.31.0.

Everything works except the SyntaxHighlight extension. The error message:

Notice: Failed to invoke Pygments: 'C:\Python36\Scripts\pygmentize.exe" "-l" "css" "-f" "html" "-O" "cssclass' is not recognized as an internal or external command, operable program or batch file.

[Called from SyntaxHighlight::highlight in C:\Apache24\htdocs\wiki\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php at line 336] in C:\Apache24\htdocs\wiki\includes\debug\MWDebug.php on line 309

The PATH is set correctly, and from a sample test php file I can call Pygments, and it works:

<?php
$output = shell_exec('C:\Python36\Scripts\pygmentize.exe -l php -f html -O cssclass C:\Apache24\htdocs\test2.php');
echo "$output";
?>

The previous version (MediaWiki 1.26.4) used an external lib for shell commands, and it has worked on Windows: use Symfony\Component\Process\ProcessBuilder;
The current MediaWiki 1.31.0 use the built-in MediaWiki Shell: use MediaWiki\Shell\Shell;

Event Timeline

I determined that it's actually the same problem: using concatenation makes the error disappear. However, this isn't a complete solution, as another problem pops out: the process starts running, but never stops. I guess it's the same as https://www.mediawiki.org/wiki/Topic:Ufijjebcmsvh2lij, for which I'm going to open a separate task.

@Daimona your last comment you said:

using concatenation makes the error disappear

Can you explain how to use concatenation as a temporary workaround for the moment?

The problem I am having is logging the following in Mediawiki (1.31.0) log:

[exec] Error running "c:\Python27\Scripts\pygmentize.exe" "-l" "sql" "-f" "html" "-O" "cssclass=mw-highlight,encoding=utf-8": 'c:\Python27\Scripts\pygmentize.exe" "-l" "sql" "-f" "html" "-O" "cssclass' is not recognized as an internal or external command, operable program or batch file.

I am runing PHP 7.0.15 (cgi-fcgi)

@Quinnj09 Yes, that's the error. T183759 provides an example of concatenation for a similar case; basically, instead of the parametration at lines 319-323 you have to uses dots, so the code will be

$result = Shell::command(
	self::getPygmentizePath() .
	'-l' . $lexer .
	'-f' . 'html' .
	'-O' . implode( ',', $optionPairs )
)