Execution of dos and linux commands through PHP code

PHP provides a functionality to execute ms-dos and linux commands through php code.

The execution operator(`) in PHP allows you to pass commands direct to the operating system for execution, then capture the results.
You can perform any commands inside back ticks (`) that you would normally perform direct from the command line, including piping output to and from and/or redirecting output through other programs.

Example 1:
print `dir`; // windows command for listing directories
Example 2:
print `mkdir hope`; // windows command for creating a directory with name hope

In this way we can use almost all the ms-dos commands in the php if the code is running on the windows server.

If the php is running in the linux server we can use the linux commands in the code.

Example :

print `ls` // linux command for listing directories

Leave a Reply

Your email address will not be published. Required fields are marked *