apelidoko
apelidoko

Reputation: 790

Running a program using shell_exec in PHP, how to know if process is done?

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,

Upvotes: 0

Views: 618

Answers (1)

Jovan Djordjevic
Jovan Djordjevic

Reputation: 91

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
}

Upvotes: 1

Related Questions