View Full Version : Running an executable under php ?

11-04-2006, 08:22 PM
Hello all.

I am using a program called jhead.exe.

It cleans up the headers from a jpg image file.

Does anyone use it ?

Is this the correct method to call the program ?:

exec("jhead -purejpg ".$source); // cleans up jpg headers

The jhead.exe file is in the same directory ans all my php scripts so I am not sure if I need to put a path in the statement or not.

Anyone with experience of this ?


11-05-2006, 05:24 AM
My guess would be fully path.

11-05-2006, 01:30 PM
Trying to us the following code failed badly with various results: like "unable to fork", "access denied", "empty results", depending on what settings I used, ... even though the same code worked from command line on the server itself.

$retstr = exec('nslookup -type=mx myhost.com', $retarr);

Instead of nslookup I believe this would apply to most programs from the \system32\ directory.

I had to learn that the following finally worked:
$retstr = exec('c:\php\safedir\nslookup -type=mx myhost.com', $retarr);

... but only under the listed preconditions:
1: nslookup.exe is placed (copied) in the directory \php\safedir\
2: the directory \php\safedir\ is included in the system PATH environement variable
3: the file cmd.exe is placed in \php\ as listed by other notes above
4: the directory "c:\php\safedir\" is set in the php.ini setting
safe_mode_exec_dir = "c:\php\safedir\"
.. maybe set in php-activescript.ini as well, depending on your system setup.
5: nslookup is referenced by the full path as otherwise the file from \windows\system32\ will be called. This happend to me with empty result due to missing rights!

Hope this helps somebody saving some time and headaches.

hope this helps

11-05-2006, 09:34 PM
That is VERY interesting - thanks for posting it. :thumbsup:

Looks like I have a bit of work to do :D