1

I'm trying to change my code from using the PHP method shell_exec() to the Symfony Component Process.

Currently, I am using as: $result = shell_exec("python3 \path\to\python.py var1 var2 var3"); to execute my python file in my laravel project.

I cannot find any way to add the var1 var2 var3 with Symfony's process. Either I am blind and can't read the doc properly, or I can't do what I need to do with Symfony Process.

https://symfony.com/doc/current/components/process.html

1 Answer 1

4

You just need to provide arguments as an array

use Symfony\Component\Process\Process;

$process = new Process(['python3', '\path\to\python.py', 'var1', 'var2', 'var3']);
Sign up to request clarification or add additional context in comments.

3 Comments

This works on my local server, I will attempt to replicated it on my production server. Thank you. Will update if needed, if not, will approve this as answer.
A follow-up question, does the entire Symfony package deal with Python modules, or is downloading them still required?
Using a Python module is nothing more than calling a terminal command, and Symfony Process is nothing more than calling a terminal command in an object way. So yeah you still have to download them.

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.