5

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.

Sildoreth
  • 1,883
  • 1
  • 25
  • 38
Arun Sivaraj
  • 333
  • 1
  • 3
  • 9
  • The solution is not to run the prompt as an administrator, but to make sure that your non-admin prompt can find it. Try entering the full path (e.g. `/usr/bin/ipconfig`), possibly finding it first using `whereis ipconfig` manually. – CompuChip Apr 01 '15 at 17:10
  • @CompuChip He is using windows. There is no `ipconfig` in linux. It's `ifconfig` – Harikrishnan Apr 02 '15 at 06:31
  • 1
    @Harikrishnan you are right of course, I was thrown off track by the `2>&1` redirection which I have typically seen in Linux systems. – CompuChip Apr 02 '15 at 06:34

0 Answers0