I am trying to learn the php shell_exec() function which I believe, enables us to run cmd commands from within a php script.But in my system, when I normally open the command prompt and type in a command, for example, ipconfig
, it says :
'ipconfig' is not recognized as an internal or external command, operable program or batch file.
So in order to avoid it, I have to right click the command prompt and select "run as administrator" and everything works fine.
Now my problem is when I try to run similar commands like ipconfig
from inside the php script, I get the same error as given above. Is there a way to solve this problem? I mean is there a way to run the cmd commands as an administrator from inside php?
I am attaching sample code below, so that you can edit it and help me out. Thanks in advance.
Here's the code :
<?php
$output = shell_exec('ipconfig 2>&1');
echo $output;
?>
Output (which I wish to avoid)
'ipconfig' is not recognized as an internal or external command,operable program or batch file.