Ayxan Amiraslanli
Ayxan Amiraslanli

Reputation: 21

Windows allow user to run commands

On windows xp I can run many commands form PHP with shell_exec() function.

I need to use OfficeToPDF on windows 10 with PHP. My php script is:

<?php
$command = 'OfficeToPDF input.docx output.pdf';
$exec = shell_exec($command);
echo $exec;
?>

This script works on windows XP Professional, but not on windows 7, 8, 10. OfficeToPdf simply opens Microsoft Word and saves file as PDF. What changed on win7, win8, win10? Why I couldn't execute this command from PHP on new OS's?

I have apache service automaticly starts from SYSTEM user.

UPDATE: But I can run OfficeToPDF input.docx output.pdf command when I open cmd window manually.

Upvotes: 0

Views: 170

Answers (1)

John Lim
John Lim

Reputation: 495

I suspect that some environment variables are missing that are required. You should try running from within a command window instance, that will setup the default env vars:


    $command = 'cmd /c OfficeToPDF input.docx output.pdf';
    $exec = shell_exec($command);
    echo $exec;

You might want to use the full path to OfficeToPDF, input.docx and output.pdf in case your default directory is incorrect, or call chdir() first.

The meaning of /C is:

/C Carries out the command specified by string and then terminates

Upvotes: 1

Related Questions