I have a Django web application running on a server (apache), and I'm trying to compile a Java file from the Python code using this:
def comp(request):
p = subprocess.Popen(['javac',filepath],stdout=subprocess.PIPE,stderr=subprocess.PIPE, bufsize=100)
res, err =p.communicate()
return HttpResponse (err)
When calling the comp method I get BadStatusLine exception. I googled about it and I found that the subprocess might be blocking when trying to reed the outputs... so I tried this code:
def comp(request):
p = subprocess.Popen(['/usr/bin/javac',filepath],stdout=subprocess.PIPE,stderr=subprocess.PIPE, bufsize=100)
while p.returncode == None:
res, err =p.communicate()
if p.returncode != 0:
err = "whatever"
return HttpResponse (err)
it's still blocking
I've tried to write the first code directly to the python interpreter and it worked fine the results are caught successfully from the outputs I guess that the subprocess block have something to do with apache maybe... honestly i don't know what to do next I've tired many methods present in the python doc http://docs.python.org/2/library/subprocess.html but none worked
Thank you for your help.