Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to open a new CMD window using PHP

Tags:

php

windows

cmd

In the last days i was tying to code something in PHP to popup a CMD windows and this CMD windows have a command like "ping google.com" and process it
i don't need the PHP code to read the result , i only want it to run it i tried some thing like

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

but no result (i don't know if it run it in background )
so i read this and i founded many ways but nothing worked

My OS is windows and thanks alot for all :)

like image 657
user3421990 Avatar asked Nov 13 '14 12:11

user3421990


People also ask

How do I open another command prompt window?

Click Start, type cmd, and press Enter to open a command prompt window. In the Windows taskbar, right-click the command prompt window icon and select Command Prompt. A second command prompt window is opened.

Can I run PHP in CMD?

After installation of PHP, we are ready to run PHP code through command line. You just follow the steps to run PHP program using command line. Open terminal or command line window. Goto the specified folder or directory where php files are present.

What is PHP command line?

PHP's Command Line Interface (CLI) allows you to execute PHP scripts when logged in to your server through SSH. ServerPilot installs multiple versions of PHP on your server so there are multiple PHP executables available to run.


1 Answers

the answer is
i searched alot 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 &");   
    } 
}
?>
like image 166
user3421990 Avatar answered Oct 18 '22 10:10

user3421990