I have written a python script (mail.py) to send email in python, and I have written another file to submit action. I need that the file mail.py should run in background. when I am writing the follwing code
$result=shell_exec('python mail.py&');
echo $result;
then there is no response but when i am running the file python mail.py & then it is running successfully
Kieran
4,0934 gold badges30 silver badges39 bronze badges
asked Aug 23, 2012 at 12:06
Rohitashv Singhal
4,56713 gold badges63 silver badges107 bronze badges
1 Answer 1
You must set full path to python's interpreter like:
shell_exec('/usr/bin/python mail.py &');
answered Aug 23, 2012 at 12:21
Denis
7,4019 gold badges41 silver badges59 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
Rohitashv Singhal
how can i check that this command is running in background or not. because still it is not sending any mail but sending using command line
Vlad Balmos
@lord_linus you can't using shell_exec. other methods include interprocess communication with mail.py, checking pid of mail.py, or make mail.py write a log and the read that log with php
Rohitashv Singhal
hey now mail is being sent but I am getting one problem that I am doing two task: one is to submit the form and display some data and another is to send a mail in background. but when i am clicking to submit the form then it is waiting for sending the mail. but i need that the data should be displayed first and it should not wait for send mail
Rohitashv Singhal
@VladBalmos whats the problem in sheel_exec()
Vlad Balmos
shell_exec returns only the output of the command after it has executed. You are executing the ptyhon script in background, thus shell_exec returns imediatly without providing any output. So you can't know for sure if execution was successful or not
default