How to open a new CMD window using PHP

In recent days, I have linked code for something in PHP to pop up CMD windows , and in CMD windows there is a command like ping google.com "and process it
I don’t need PHP code to read the result, I want it to run it I tried something like

<?php     
exec('C:\Windows\System32/cmd.exe ping google.com');     
<?

but there is no result (I don’t know if it runs it in the background)
so I read this one and I founded many ways, but nothing worked

My OS is windows and thank you very much for everything :)

+4
source share
2 answers

the answer is - I searched a lot to find it :))

<?
execInBackground('start cmd.exe @cmd /k "ping google.com"');



function execInBackground($cmd) { 
    if (substr(php_uname(), 0, 7) == "Windows"){ 
        pclose(popen("start /B ". $cmd, "r"));  
    } 
    else { 
        exec($cmd . " > /dev/null &");   
    } 
}
?>
+9

? , PHP cmd. : https://github.com/merlinthemagic/MTS

:

//if you prefer Powershell, replace 'cmd' with 'powershell'
$shellObj    = \MTS\Factories::getDevices()->getLocalHost()->getShell('cmd');

$strCmd1   = 'ping -n 4 www.google.com';
$return1   = $shellObj->exeCmd($strCmd1);

return OR error cmd, .

, , $shellObj, PHP script. script exeCmd(), .

0

All Articles