0

I am trying to run the command prompt using a php script on camps but I am unable to do it.

I could run the Explorer using

exec("explorer");

But when I try to run

exec("C:\Windows\system32\cmd.exe");

It doesn't execute How do it do it?

I want to run a command like

ping Google.com 
Karan Jain
  • 405
  • 1
  • 7
  • 12

2 Answers2

0

This reads commands from the standard input and executes them:

while (true) {
    $command = readline("Command: ");
    passthru($command);
}

Note that if you run a command like ping, you might not be able to stop it this way (usually you would hit Ctrl + C). However you can specify the number of pings to send:

ping -c 3 google.com
minipif
  • 4,756
  • 3
  • 30
  • 39
0

You can use the "exec()" function to run the code in background. The command prompt won't be displayed but will directly run the code.

Now if you had to run a python script from php:

You could use

exec("py "location of python script");
exec('py C:\xampp\htdocs\pro\helloworld.py');

The output would be in the directory where your php script is present.

Karan Jain
  • 405
  • 1
  • 7
  • 12