Is it possible to run windows command line code from php ? My windows command line code is:
C:\xampp\mysql\bin>mysqlbinlog
is not a command.
I think you mean C:\xampp\mysql\bin\mysqlbinlog
.
Notice the replacing of the >
in a \
.
The >
is only visible in the command prompt as a separator (for the eyes) but you should not use it like that in a command unless you are trying to redirect your output. (which you are doing again later in the line). So just replace that first >
in a \
and your command will run.
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!
Just give it a try. Or if you want a sandbox example just try to run
<?php echo exec("whoami");?>
If you can't run the command directly in exec(), then what you can do is make a batch file with the command and place it on the root of your website. Then, just run:
<?php echo exec("script.bat"); ?>
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 :-)