Bonjour,
je voudrais réaliser avec Symfony2 ce qui fonctionne avec du PHP simple. C'est à dire réaliser un string shell_exec ( string $cmd ).

J'ai essayé avec Process. Mais je n'ai rien et pas de message d'erreur?
Voici mon code dans mon controller:

/**
     * Ouvrir un  *.doc document.
     *
     * @Route("/{donum}/open", name="dossier_open")
     * @Method("GET")
     * @Template()
     */
    public function opendocAction($donum)
    {
        $em = $this->getDoctrine()->getManager();

        $entity = $em->getRepository('AppBundle:Dossiers')->findOneBy(array('donum' => $donum));

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Dossiers entity.');
        }
        $ext = $entity->getDoassur()->getAssext();

        // pour Mac
        //$action = "open ";
        //$path = "/Users/christianzirbes/Documents/exdoc_dossiers/";
        //$ext = $ext."/";

        // pour windows
        $action = '"C:\\Program Files (x86)\\LibreOffice 4\\program\\swriter.exe" ';
        $path = "C:\\Users\\ZIRBES\\Documents\\Compagnies\\";
        $ext = $ext."\\";

        $dossier = $donum.".doc";

        $output = $action.$path.$ext.$dossier;

        $process = new Process($output);
        $process->run();

        // executes after the command finishes
        if (!$process->isSuccessful()) {
            throw new \RuntimeException($process->getErrorOutput());
        }

       $processOutput =  $process->getOutput();

       return array('output' => $processOutput);

       //return $this->redirect($this->generateUrl('dossiers_show', array('donum' => $donum)));
    }

Une idée?

je suis en localhost,
Windows 10,
Wamp,
Symfony2.7

2 réponses


Salut
Qu'est ce que ça donne quand tu debug process ?
et je précise au cas ou mais tu as bien mis ça dans ton controller ?

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
zirby
Auteur

Merci pour ta réponse.
j'ai une exception:

 The process ""C:\Program Files (x86)\LibreOffice 4\program\swriter.exe" C:\Users\ZIRBES\Documents\Compagnies\mg\56953.doc" exceeded the timeout of 60 seconds.
500 Internal Server Error - ProcessTimedOutException 

Alors que le fichier existe à cet endroit et que quand je lance la phrase dans un terminal ça fonctionne ??