Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 8, 2009, 22:46   #1
PHPycho
SitePoint Guru
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 644
how to use exec() in windows

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

<?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:
Quote:
'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
PHPycho is offline   Reply With Quote
Old Nov 9, 2009, 00:01   #2
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 461
Quote:
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
Shrapnel_N5 is online now   Reply With Quote
Old Nov 9, 2009, 00:48   #3
PHPycho
SitePoint Guru
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 644
I would like to know the list of such commands that window supports.
PHPycho is offline   Reply With Quote
Old Nov 9, 2009, 01:02   #4
Rubble
SitePoint Guru
 
Rubble's Avatar
 
Join Date: Dec 2005
Location: Cambridge, England
Posts: 781
You will probably need to change the ' to " if using in exec in a windows enviroment.
Rubble is online now   Reply With Quote
Old Nov 9, 2009, 02:28   #5
PHPycho
SitePoint Guru
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 644
Quote:
Originally Posted by Rubble View Post
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
PHPycho is offline   Reply With Quote
Old Nov 9, 2009, 02:39   #6
AnthonySterling
Previously, SilverBulletUK.
 
AnthonySterling's Avatar
 
Join Date: Apr 2008
Location: North-East, UK.
Posts: 2,917
whoami isn't a valid windows operation.
AnthonySterling is offline   Reply With Quote
Old Nov 9, 2009, 03:15   #7
Jake Arkinstall
Formerly 'arkinstall'
 
Jake Arkinstall's Avatar
 
Join Date: May 2006
Location: Powys, Mid Wales
Posts: 6,173
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.
Jake Arkinstall is offline   Reply With Quote
Old Nov 9, 2009, 03:21   #8
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 461
Quote:
I would like to know the list of such commands that window supports.
there are hundreds of thousands.
not sure you want it all
Shrapnel_N5 is online now   Reply With Quote
Old Nov 9, 2009, 03:26   #9
PHPycho
SitePoint Guru
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 644
Thanks arkinstall.
you let me know the concept.
I tried to run the command (ipconfig : which works from windows command line) as:
PHP Code:

echo exec("ipconfig"); 

Running the code gave the result:
Quote:
Default Gateway . . . . . . . . . : 192.168.192.X
PHPycho is offline   Reply With Quote
Old Nov 9, 2009, 03:59   #10
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 461
Same concept as in unix. Exactly
Shrapnel_N5 is online now   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 15:27.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved