php exec missing output

exec, nltk, php, python

Solution

2>&1 needs to be added in the command to get the complete output. This solved my problem.

Problem

I am trying to execute the python script for POS tagging through PHP. But its not returning the full output. Python script: ``` import nltk import sys text = sys.argv[1] tokenize_into_words = nltk.word_tokenize(text) print text result = nltk.pos_tag(tokenize_into_words) print result print "Done!" ``` PHP script ``` $cmd = 'python /Library/WebServer/Documents/varticle/vcmdpos.py ' . $string2; $tmp = exec($cmd,$output); print_r($output); ``` Command: python /Library/WebServer/Documents/varticle/vcmdpos.py Scientists Observed Output: Array ( [0] => Scientists ) Expected Ouput: Array ( [0] => Scientists [1] => "[('Scientists', 'NNS')]" [2] => "Done!") When I run the command manually it takens around 5-10 sec to run. [This may be due to the time required to do POS tagging or importing nltk.] But when run through PHP it immediately returns and output from nltk.pos_tag or print statement after it is not returned. Am I missing something?

Original source