0

Hi I am running a python script inside PHP using the shell_exec command, However how would I know if the execution of the python has been completed already?

Here is portion of my code

$py_path = 'app/public/engines/validation/delta';        
chdir($py_path);                    
$py_var = 'python scraped_data.py';                   
$exec = shell_exec($py_var);

How would I know if the python is finished its processing? I wanted to know because I have a series of processes to run but it needs the first process to be completed first.

Thank You,

1 Answer 1

1

If you check php.net description of shell_exec() is:

shell_exec — Execute command via shell and return the complete output as a string

So you can edit your python script to output true or 1 once script is finished.

then you can simply code something like this:

$py_path = 'app/public/engines/validation/delta';        
chdir($py_path);                    
$py_var = 'python scraped_data.py';                   
$exec = shell_exec($py_var);
If($exec){
//Execute another script or do what you wish
}
Sign up to request clarification or add additional context in comments.

1 Comment

Can you help me on why my shell_exec does not work for my python command, stackoverflow.com/questions/65612905/… Thank You

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.