-2

I am trying to run cmd command exec and system via php code, but it is showing me nothing. Is there anything I need to enable in php.ini???

User27
  • 535
  • 5
  • 25

1 Answers1

3

1 - it depend on what you write inside exec()

and This command only executed on the server side , and cannot be executed on the client side

to use this command : - for example u can write : <?php echo exec("ping google.com"); ?> to know the ping of google and the result will appear in your browser page
- use shell_exec("ping google.com"); to show more detail
- Another Example to use that command : shell_exec('systeminfo | findstr /B /C:"OS Name"');
to show what operation system u use.

Another solution is to create a bat file , name it : "Simple.bat" and save it on the root of your website
then simply use this command to call it : <?php echo exec("Simple.bat"); ?>

2 - if you ruining IIS the issues could be something inside your settings and the causes are many when u come to this part , and i dont have Experience at IIS , * only Apache but one of the solutions suggest about IIS can be founded here in first reply :
https://forums.iis.net/t/1216283.aspx

The Doctor
  • 636
  • 1
  • 7
  • 23
  • also not working. Error:- exec(): Unable to fork [ping google.com] – User27 Jan 30 '17 at 00:28
  • sorry, can you pls tell me how to check if server have previlege to run an external application? bcoz not a single cmd command running from my website. I am using IIS. – User27 Jan 30 '17 at 00:38
  • @pk27 what u runing your pc on : windows or linux ? - and what PHP version u have – The Doctor Jan 30 '17 at 00:38
  • windows and PHP 5.2.0 – User27 Jan 30 '17 at 00:41
  • @pk27 write this command `echo system("ulimit -a");` then tell me what message show to you . – The Doctor Jan 30 '17 at 00:53
  • warning:- system(): Unable to fork [ulimit -a] – User27 Jan 30 '17 at 01:03
  • Actually I need to access a shared folder which has username and pwd. for that I need to use system("net use ", ....); command. But it is just not running :( – User27 Jan 30 '17 at 01:06
  • @pk27 look for this file on your system : " **php.ini** " open it and press Ctrl + F , then search for " **memory_limit** " and increase the size of that option make it 100m or more , depend on what u need // for me 200m is enough ; – The Doctor Jan 30 '17 at 01:18
  • It was 128M, I changed to 200M, but still showing the same warnings, can't run exec/system, net use etc – User27 Jan 30 '17 at 02:07
  • @pk27 it could be from your local server IIS software . uninstall it and change it with apache :: **Download and install Apache 2.2 or higher** , then put your code page in `www` directory inside apache folder and run your page `localhost/yourpage.php` from any Browser and it should run fine . Last Versions for Pc : http://directory.apache.org/studio/download/download-windows.html – The Doctor Jan 30 '17 at 02:37
  • 1
    It worked after doing this: https://forums.iis.net/t/1216283.aspx – User27 Jan 30 '17 at 03:40
  • Thanks for your time – User27 Jan 30 '17 at 03:41
  • @pk27 so the issues was on IIS software as i expect in the last comment , good to know that u fix it . – The Doctor Jan 30 '17 at 10:31