How to use exec() in windows

I have run exec() method in windows using the following script:


<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>

which is given in the php manual: http://www.php.net/manual/en/function.exec.php

but i saw nothing in the output.Rather i saw the following line the log file:

‘whoami’ is not recognized as an internal or external command,operable program or batch file.

Since i haven’t use this exec() command. I was just exploring it. I would like to know the things to be considered while using this exec() in windows.

Thanks

I would like to know the things to be considered while using this exec() in windows.

Executing command must be an internal or external command, operable program or batch file.

CY, Captain Obvious

I would like to know the list of such commands that window supports.

You will probably need to change the ’ to " if using in exec in a windows enviroment.

Nope that didn’t do a trick.
If i run the same code in linux it outputs: apache

whoami isn’t a valid windows operation. :wink:

Exec simply runs a command on the system.

A simple way to see what works and what doesn’t is to open the command line on the operating system.

On windows, you can access the command line by hitting the windows key + ‘R’, then typing ‘cmd’ and hitting enter - that’ll open up command prompt.

On Linux it depends on your distro, but assuming you’re using one with the default Gnome menu, it’ll usually be under ‘Applications’ : ‘Accessories’ : ‘Terminal’.

PHP’s exec function simulates you typing the command into that terminal.

I would like to know the list of such commands that window supports.

there are hundreds of thousands.
not sure you want it all :slight_smile:

Thanks arkinstall.
you let me know the concept.
I tried to run the command (ipconfig : which works from windows command line) as:

echo exec("ipconfig");

Running the code gave the result:

Default Gateway . . . . . . . . . : 192.168.192.X

Same concept as in unix. Exactly