1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <?php
namespace Cat\AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* @Route("pro/")
*/
class ProcessTestController extends Controller
{
/**
* @Route("test/")
*/
public function test()
{
$executableShellScript = '/srv/cat/www/htdocs/symfony_process/GUIImages/create.sh';
$process = new Process($executableShellScript);
try {
$process->setWorkingDirectory('/srv/cat/www/htdocs/symfony_process/');
$process->mustRun();
echo $process->getOutput();
} catch
(ProcessFailedException $e) {
echo $e->getMessage();
}
if($process->isSuccessful()) {
echo file_put_contents('/srv/cat/www/htdocs/symfony_process/ProcessOutput/tess6st.txt', $executableShellScript. ' is '. $process->getExitCodeText());
} else {
echo file_put_contents('/srv/cat/www/htdocs/symfony_process/ProcessOutput/errortest.txt', $process->getErrorOutput());
}
return $this->render('AppBundle::layout.html.twig');
}
} |
Partager