Home » Php » Using PHP to execute cmd commands

# Using PHP to execute cmd commands

Questions:

How do I properly execute commands in the command line using php? For example I’m using the command below in the command line to convert a docx file into a pdf file:

pdfcreator.exe /PF"D:\Documents\sample.docx


Now using PHP code I want to be able to execute the same command but nothing seems to be happening:

<?php
shell_exec('pdfcreator.exe /PF"D:\Documents\sample.docx"');
?>


Is this possible in PHP?If yes, how do I do it?

system("c:\path\to\pdfcreator.exe /PF\"D:\Documents\sample.docx"");

command // back ticks drop you out of PHP mode into shell
exec('command', $output); // exec will allow you to capture the return of a command as reference shell_exec('command'); // will return the output to a variable system(); //as seen above.  Also, make sure your .exe is included within your$PATH variable. If not, include the full path for the command.