Python程序没有从php执行

时间:2017-05-01 13:28:02

标签: php python

我开发了一个脚本来从给定的文本中提取实体,并且脚本执行正常。

python代码:

   from nltk.tag import StanfordNERTagger
   from nltk.tokenize import word_tokenize
   with open('C:\\pythonScripts\\input.txt', 'r') as f:
       sample = f.read()
  import nltk
  def list_tokens(sampletext):
      nltk.internals.config_java("C:\\Program Files\\Java\\jdk1.8.0_131\\bin\\java.exe")

      classifier='C:\\Users\\gsrilakshmi.INDIA\\Desktop\\stanford\\stanford-ner-2016-10-31\\classifiers\\english.all.3class.distsim.crf.ser.gz'

      jar='C:\\Users\\gsrilakshmi.INDIA\\Desktop\\stanford\\stanford-ner-2016-10-31\\stanford-ner.jar'

      st = StanfordNERTagger(classifier,jar,encoding='utf-8')

     tokenized_text = word_tokenize(sampletext)
     classified_text = st.tag(tokenized_text)

     with open('C:\\pythonScripts\\output.txt', 'w') as fp:
        fp.write('\n'.join('%s %s' % x for x in classified_text))

     return classified_text


tokens = list_tokens(sample)
print(tokens)

从php调用python脚本时,不会生成输出文件。

php代码:

$pyscript = 'C:\\Python\Python36-32\python C:\pythonScripts\sample1.py';
$python = 'C:\Python\Python36-32\python.exe';

$p=exec($pyscript,$fulloutput);
exec("python  C:\\pythonScripts\\sample1.py > C:\\pythonScripts\\out.txt");

echo $ p; 我得到了输出:'[找到C:\ Program Files \ Java \ jdk1.8.0_131 \ bin \ java.exe:C:\ Program Files \ Java \ jdk1.8.0_131 \ bin \ java.exe]'

请帮我解决这个问题。

谢谢, Srilu

0 个答案:

没有答案