当执行来自php的终端命令时,需要将终端执行显示为弹出窗口或类似流的视频。要将输出显示到浏览器中,就像this.But一样,还必须像在控制台中一样显示输出。
$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>';但需要像弹出窗口一样显示执行过程。有可能吗?
使用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;得到这样的输出。
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发布于 2017-02-28 02:52:44
MTS可以让你返回一个命令。然而,在您的示例中,您将(empty)返回传递给PhantomJS headless浏览器,而不是传递给发出请求的客户机。
以下是更正后的示例:
//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;https://stackoverflow.com/questions/41588211
复制相似问题