1

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();
2
  • Possible duplicate of stackoverflow.com/questions/62726532/… Commented Feb 28, 2022 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. Commented Feb 28, 2022 at 15:39

1 Answer 1

3

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]);
Sign up to request clarification or add additional context in comments.

1 Comment

Maybe $process->wait() needed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.