2017-07-27 1 views
0

Ich versuche, den Text auf dem ots Summierer auf Ubuntu einzugeben. Ich benutze die python2 subprocess Bibliothek. Aber konsequent die folgende Fehlermeldung erhalten:Subprozess in Python2 gibt Fehler

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 

Auch habe ich gelesen, dass die ots nimmt die Eingabe aus der Datei oder die stdin. Daher habe ich versucht, Eingang zu setzen, wie:

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

Aber immer die folgende Ausgabe:

"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" 

Aber es ist nicht das, was ich zu erreichen versuchen. Ich möchte nur den Text in die ots-Bibliothek mit dem subprocess von Python eingeben. Ist das ein Weg dies zu tun und die Zusammenfassung aus der ots schneller zu bekommen? Bitte, hilf mir.

+0

''ots --ratio = 30 <' + text' verwendet die Zeichenfolge in' text' als Dateiname, von dem gelesen werden soll. Ich weiß nicht "ots", vielleicht hat es eine Möglichkeit, eine Zeichenfolge von der Befehlszeile zu akzeptieren. Wenn nicht, könnten Sie eine Kommandozeilen-Zeichenfolge übergeben, als ob sie aus einer Datei kommen würde, indem Sie eine [here string] (http://tldp.org/LDP/abs/html/x17837.html) verwenden: ''ots - -ratio = 30 <<< '+ text', aber du musst 'subprocess' sagen,' bash' anstelle von 'sh' zu verwenden, da' sh' hier keine Strings unterstützt. –

Antwort

0

Ich glaube, Sie brauchen die | Rohrbediener.

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

< Das Symbol in schlag wird take Eingabe von einem anderen Strom verwendet.

+0

immer folgende Fehlermeldung: 'Traceback (jüngste Aufforderung zuletzt): File "" Linie 1 in File "/usr/lib/python2.7/subprocess.py", Linie 567, in check_output Prozess = Popen (stdout = PIPE, * popenargs, ** kwargs) Datei "/usr/lib/python2.7/subprocess.py", Zeile 711, in __init__ errread, errrite) Datei "/ usr/lib/python2 .7/subprocess.py ", Zeile 1343, in _execute_child raise child_exception OSError: [Errno 2] Keine solche Datei oder kein Verzeichnis ' –

+1

@JafferWilson Jetzt versuchen? Ich glaube, ich habe 'shell = True' vermisst –

Verwandte Themen