Is it possible to run windows command line code from php ? My windows command line code is:
<?php
error_reporting(E_ALL);
try {
echo exec('C:\xampp\mysql\bin>mysqlbinlog --start-datetime="2011-04-21 10:31:44" c:\xampp\mysql\data\binlog\bin-log.000001 > c:\xampp\mysql\data\binlog\sql.txt');
} catch (Exception $e) {
echo $e->getMessage();
}
Now I want to run this code from PHP using system()
or exec()
etc.
any help appreciated.
The shell_exec() function is an inbuilt function in PHP which is used to execute the commands via shell and return the complete output as a string. The shell_exec is an alias for the backtick operator, for those used to *nix.
system() is just like the C version of the function in that it executes the given command and outputs the result. The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.
PHP does not come pre-installed on Windows systems. To work with PHP on Windows, PHP will need to be manually downloaded and installed. You can download PHP from the PHP download page at http://www.php.net/downloads.php. Download the zip package from the "Windows Binaries" section.
If you are able to run your commands manually from the command-line, but not via WAMP, than the user the Apache Service runs as does not have the needed permissions to execute your commands and binaries (nor interact with the desktop if it is GUI related).
By default, Apache service run under user account: nt authority\system
Change it to your custom user (user with administrative rights) by following below steps,
Happy coding :-)
I'm using wamp, and the only solution was the followings:
At Control Panel / Administrative tools / Services, search for wampapache64, httpd, or something like that. On the Log On tab tick the 'allow service to interact with desktop'
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With