SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    '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

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would like to know the list of such commands that window supports.

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,397
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    You will probably need to change the ' to " if using in exec in a windows enviroment.

  5. #5
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    whoami isn't a valid windows operation.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would like to know the list of such commands that window supports.
    there are hundreds of thousands.
    not sure you want it all

  9. #9
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    Default Gateway . . . . . . . . . : 192.168.192.X

  10. #10
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Same concept as in unix. Exactly


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •