Reputation: 107
Need to show the terminal execution as a popup or video like streaming when executed the terminal commands from php. To get the output to the browser did like this.But have to show the output as in console also.
$script= 'cd /var/www/html/project_direcoty;java -cp <script>;
while(@ob_end_flush());
ini_set('implicit_flush', true);
ob_implicit_flush(true);
$proc = popen($script,'r');
echo '<pre>';
while(!feof($proc)){
echo fread($proc, 4096);
@ flush;
}
ob_flush();
$_SESSION['case_id']= '';
echo '</pre>';
but need to show the execution like a popup. Is it possible?
Modified the code using MTS
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', false);
$shell->exeCmd('cd /var/www/html/folderpath');
$cmd = 'java -cp "libs/*:bin" org.testng.TestNG '.$cases['case_id'].' 2>&1';
$return1 = $shell->exeCmd($cmd);
$windowObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($return1);
$width = 640;
$height = 480;
$windowObj->setSize($width, $height);
$windowObj->close();
$shell->terminate();
echo $return1;
Got the output like this.
Fatal error: Uncaught Exception: MTS\Common\Devices\Shells\Bash::shellStrExecute>> Read data timeout in /var/www/html/MTS/MTS/Common/Devices/Shells/Bash.php:81 Stack trace: #0 /var/www/html/MTS/MTS/Common/Devices/Shells/Base.php(89): MTS\Common\Devices\Shells\Bash->shellStrExecute('java -cp "libs/...', '\\[bash\\.58787dd...', 10000) #1 /var/www/html/Sandbox_oway/admin/run-test-cases.php(84): MTS\Common\Devices\Shells\Base->exeCmd('java -cp "libs/...') #2 {main} thrown in /var/www/html/MTS/MTS/Common/Devices/Shells/Bash.php on line 81
Upvotes: 0
Views: 1062
Reputation: 605
MTS can get you the return of a command. However in your example you are passing the (empty) return to the PhantomJS headless browser and not to the client that made the request.
Here is a corrected example:
//you will get the "Read data timeout" exception if your command takes longer than the default timeout in milisecs. make sure the value is high enough.
$timeOut = 100000;
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', false);
$shell->exeCmd('cd /var/www/html/folderpath');
$cmd = 'java -cp "libs/*:bin" org.testng.TestNG '.$cases['case_id'].' 2>&1';
$return1 = $shell->exeCmd($cmd, null, $timeOut);
$shell->terminate();
//the return from your command, however since you are redirecting the output/error pipes (2>&1) this variable will be empty. If your command displays data, remove the redirect to get data.
echo $return1;
Upvotes: 0
Reputation: 107
Did through additional way by saving the popen output to a text file and later by making ajax call showing the file output to the html.
Upvotes: 0
Reputation: 3037
You can use MTS
It's a tool set for PHP. Currently comprised of two core components shell and browser.This project strives to give developers the tools that let them automate processes that were designed for people.
Please read about the requirements and installation from the GitHub wiki.
In your case, You need to show in a new window. Yes, you can show.
Here, It is using PhantomJS.You can open a website and execute standard functions against it with PHP.
//Some websites are either far away or just slow, so it is a good idea to up the allowed execution time.
ini_set('max_execution_time', 120);
//Get a new browser window:
$myUrl = "https://www.yourwebsite.com/";
$windowObj = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($myUrl);
$windowObj
now contains a browser window with your website loaded.
You can Read more from this page.
Upvotes: 1