Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PHP to execute cmd commands

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?

like image 532
Wern Ancheta Avatar asked Jun 26 '12 14:06

Wern Ancheta


People also ask

Can PHP be used for command line scripts?

As of version 4.3. 0, PHP supports a new SAPI type (Server Application Programming Interface) named CLI which means Command Line Interface. As the name implies, this SAPI type main focus is on developing shell (or desktop as well) applications with PHP.

How do I pass a command line argument in PHP?

To pass command line arguments to the script, we simply put them right after the script name like so... Note that the 0th argument is the name of the PHP script that is run. The rest of the array are the values passed in on the command line. The values are accessed via the $argv array.

How do I run a command prompt in HTML?

Command prompt Editor: if you are using Windows OS then you can click on Start— > Run — > CMD, this will open up Command prompt Editor, where you can write HTML Programs and can save them on your computer with t. html extension.


1 Answers

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

try this.

like image 75
Piotr Olaszewski Avatar answered Oct 13 '22 02:10

Piotr Olaszewski