简体   繁体   English

python2中的子进程返回错误

[英]Subprocess in python2 returns error

I am trying to input the text to the ots summerizer on Ubuntu. 我正在尝试将文本输入到Ubuntu上的ots I am using the python2 subprocess library. 我正在使用python2 subprocess进程库。 But consistently getting the following error: 但是始终出现以下错误:

text = "the shards that cut me the deepest were the ones that intended to cut , obama to melania trump as first lady 's largest public appearance since the 2016 election - speaking in front of more than 8,000 people at the women 's foundation of colorado 's 30th anniversary celebration - and she touched on personal attacks that she faced again and again"
>>> sum = subprocess.check_output('ots --ratio=30 <' + text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/subprocess.py", line 567, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 36] File name too long

Even I have read that the ots takes input from the file or the stdin . 甚至我已经读过ots从文件或stdin接受输入。 Hence I tried to put input as: 因此,我尝试将输入内容设置为:

sum = subprocess.check_output(['echo',text,'> stdin'])

But getting the following output: 但是得到以下输出:

"the shards that cut me the deepest were the ones that intended to cut , obama to melania trump as first lady 's largest public appearance since the 2016 election - speaking in front of more than 8,000 people at the women 's foundation of colorado 's 30th anniversary celebration - and she touched on personal attacks that she faced again and again > stdin\n"

But it is not what I am trying to achieve. 但这不是我要实现的目标。 I just want to input the text to the ots library using the subprocess of python. 我只想使用python的subprocess ots将文本输入到ots库。 Is theer a way to do that and get the summary from the ots faster? 这是一种这样做的方法,可以更快地从ots获取摘要吗? Kindly, help me. 请帮帮我。

I believe you need the | 相信您需要| pipe operator. 管道操作员。

sum = subprocess.check_output('echo {} | ots --ratio=30'.format(text), shell=True)

The < symbol in bash is used take input from another stream. bash中的<符号用于从另一个流获取输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM