Run windows command in php

前端 未结 5 918
梦毁少年i
梦毁少年i 2021-02-08 15:20

Is it possible to run windows command line code from php ? My windows command line code is:



        
相关标签:
5条回答
  • 2021-02-08 15:42

    C:\xampp\mysql\bin>mysqlbinlog is not a command.

    I think you mean C:\xampp\mysql\bin\mysqlbinlog.

    Notice the replacing of the > in a \.

    The > is only visible in the command prompt as a separator (for the eyes) but you should not use it like that in a command unless you are trying to redirect your output. (which you are doing again later in the line). So just replace that first > in a \ and your command will run.

    0 讨论(0)
  • 2021-02-08 15:44

    I'm using wamp, and the only solution was the followings:

    At Control Panel / Administrative tools / Services, search for wampapache64, httpd, or something like that. On the Log On tab tick the 'allow service to interact with desktop'

    Hope this helps!

    0 讨论(0)
  • 2021-02-08 15:50

    Just give it a try. Or if you want a sandbox example just try to run

    <?php echo exec("whoami");?>
    
    0 讨论(0)
  • 2021-02-08 15:52

    If you can't run the command directly in exec(), then what you can do is make a batch file with the command and place it on the root of your website. Then, just run:

    <?php echo exec("script.bat"); ?>
    
    0 讨论(0)
  • 2021-02-08 15:56

    If you are able to run your commands manually from the command-line, but not via WAMP, than the user the Apache Service runs as does not have the needed permissions to execute your commands and binaries (nor interact with the desktop if it is GUI related).

    By default, Apache service run under user account: nt authority\system

    Change it to your custom user (user with administrative rights) by following below steps,

    1. Hit Windows+R which opens Run
    2. Type "services.msc" which opens list of windows services
    3. Find and select your apache service and open its properties
    4. Go to Logon tab and change the account From “Local System” to another user/account
    5. Restart your Apache service

    Happy coding :-)

    0 讨论(0)
提交回复
热议问题