Note that there are some explanatory texts on larger screens.

plurals
  1. POexec(): quoting full command in Windows
    primarykey
    data
    text
    <p>I've written a web application that makes use of <a href="http://php.net/exec" rel="nofollow">exec()</a> in order to run an external program. The program path is configurable and can be expected to have spaces on its name. As we all know, the Windows command prompt accepts spaces in file names or parameteres, you just have to double quote them:</p> <pre><code>C:\&gt;C:\Archivos de programa\GraphicsMagick-1.3.12-Q16\gm.exe "C:\Archivos" no se reconoce como un comando interno o externo, programa o archivo por lotes ejecutable. C:\&gt;"C:\Archivos de programa\GraphicsMagick-1.3.12-Q16\gm.exe" GraphicsMagick 1.3.12 2010-03-08 Q16 http://www.GraphicsMagick.org/ </code></pre> <p>So far so good. The issue I'm facing is the usage of the exec() PHP function itself. Certain Windows servers require that you enclose the full command <strong>(program + arguments)</strong> in double quotes:</p> <pre><code>exec('""C:\Archivos de programa\GraphicsMagick-1.3.12-Q16\gm.exe" version"'); </code></pre> <p>... and other Windows servers require <strong>not</strong> to use double quotes:</p> <pre><code>exec('"C:\Archivos de programa\GraphicsMagick-1.3.12-Q16\gm.exe" version'); </code></pre> <p>I can read the <code>PHP_OS</code> constant to detect whether the server runs Windows but I don't know what's the rule behind the quotes or not quotes subject. It if's explained in the PHP manual I cannot find it.</p> <p>Is is possible to determine programmatically if quotes are needed so I don't need to configure manually each instance of the application?</p> <p><strong>Update #1:</strong> I was being misunderstood so I've reworded parts of the question to make it more clear.</p> <p><strong>Update #2:</strong> I found <a href="http://www.php.net/manual/en/ref.exec.php#80721" rel="nofollow">a comment in the PHP manual</a> that explains the exact reason why extra quotes are needed (PHP issues an internal call to <code>cmd /c</code>). I still don't know why this appears to be true or false depending on the system.</p>
    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.
 

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