Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've written this quick and dirty workaround:</p> <pre><code>&lt;?php class Thumb{ const GM_PATH = 'C:\\Archivos de programa\\GraphicsMagick-1.3.12-Q16\\gm.exe'; /** * Quote full command if required by server (program + arguments) */ private static function quoteFullCommand($command){ // Test only once per script static $extra_quotes_required=NULL; if( is_null($extra_quotes_required) ){ if(PHP_OS=='WINNT'){ // This call will be correct (0) if and only if the server requires extra quotes exec('""sort" /?"', $output, $return); $extra_quotes_required = $return==0; }else{ $extra_quotes_required = FALSE; } } if($extra_quotes_required){ $command = '"' . $command . '"'; } return $command; } /** * Return output from "gm version" */ public static function graphicsMagickVersion(){ $command = escapeshellarg(self::GM_PATH) . ' version '; $command = self::quoteFullCommand($command); exec($command, $output, $return); return trim(implode(PHP_EOL, $output)); } } </code></pre> <p>However, it'd be way better to predict it from PHP version or server OS so links to documentation or further tips are welcome.</p> <p><strong>Update:</strong> I've had a look at the piece of PHP source code that takes care of running external commands in Windows:</p> <p><a href="http://svn.php.net/viewvc/php/php-src/trunk/TSRM/tsrm_win32.c" rel="nofollow">http://svn.php.net/viewvc/php/php-src/trunk/TSRM/tsrm_win32.c</a></p> <p>The following line adds the extra comas to the full command:</p> <pre><code>sprintf(cmd, "%s /c \"%s\"", TWG(comspec), command); </code></pre> <p>According to the file history, that line was first added on 29th May 2008 (<a href="http://svn.php.net/viewvc?view=revision&amp;revision=260429" rel="nofollow">r260429</a>):</p> <blockquote> <p>MFH: Fix bug when command is quoted and parameters are quoted during call to exec, the result is that cmd.exe /c strips the first and last quote.</p> </blockquote> <p>The following PHP releases were 5.3.0 and 5.2.7 but the line is in the 5_3 branch and not in the 5_2 one. I'm not familiar enough with PHP development process so I can't find the changelog or tell out to which exact PHP releases the fix was ported to but I'd dare say that it was a bug in PHP and it was fixed in PHP/5.3.0 (yet it wasn't backported to 5.2 so they didn't break legacy stuff).</p> <p>So my workaround is probably overkill. You just need to test the PHP OS and version:</p> <pre><code>if( PHP_OS=='WINNT' &amp;&amp; version_compare(PHP_VERSION, '5.3.0', '&lt;') ){ $command = $command = '"' . $command . '"'; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload