0

Hi everyone who i can i pass laravel parameter with symfony process code i use it to run python script

use Symfony\Component\Process\Process; 
use Symfony\Component\Process\Exception\ProcessFailedException; 
 
$process = new Process(['python3','/path/to/your_script.py',$policyname); 
$process->run();
gp_sflover
  • 3,460
  • 5
  • 38
  • 48
  • Possible duplicate of https://stackoverflow.com/questions/62726532/how-to-use-symfony-process-with-python-w-variables – Vincent Decaux Feb 28 '22 at 15:00
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Feb 28 '22 at 15:39

1 Answers1

2

yes you can pass laravel parameter to python.

  1. You need to install symfony/process using following command:

    composer require symfony/process
    
  2. you can use it in laravel as

    use Symfony\Component\Process\Process;
    use Symfony\Component\Process\Exception\ProcessFailedException;
    
    $process = new Process(['python', '/path/to/script.py']);
    $process->run();
    
    // error handling
    if (!$process->isSuccessful()) {
       throw new ProcessFailedException($process);
    }
    
    $output_data = $process->getOutput();
    

If you want to pass parameters to python, do this:

$process = new Process(['python', '/path/to/script.py', $arg]);