Estou experimentando o Gtk + 3 e estou criando um programa que obtém a saída do comando dpkg --get-selections
e o exibe em um Gtk + 3 TextView
.
Quando executo meu programa, recebo o seguinte erro:
Traceback (most recent call last):
File "file1.py", line 36, in <module>
window = dpkgApp()
File "file1.py", line 24, in __init__
with open("", "w") as f:
IOError: [Errno 2] No such file or directory: ''
dpkg: error: error writing to '<standard output>': Broken pipe
Este é o meu código:
#!/usr/bin/python
import io, subprocess, os
from gi.repository import Gtk
class dpkgApp(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Software/dependencies")
self.table = Gtk.Table(3, 3, True)
self.add(self.table)
self.scrollWindow = Gtk.ScrolledWindow()
self.table.attach(self.scrollWindow, 0, 1, 0, 1)
self.textView = Gtk.TextView()
self.scrollWindow.add(self.textView)
#######################################################################
subprocess.call("dpkg --get-selections", shell=True)
dpkg_output = os.popen("dpkg --get-selections")
with open("", "w") as f:
f.writeline(dpkg_output)
f.close()
buffer = Gtk.TextBuffer()
self.textView.get_buffer(buffer)
self.textView.set_editable(False)
self.textView.set_wrap_mode(True)
self.textView.set_cursor_visible(False)
buffer.set_text(dpkg_output)
window = dpkgApp()
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
Procurando no StackOverflow, parece haver um problema com subprocess
, mas estou usando o módulo os
para obter a saída do comando dpkg
- e a saída do erro inclui dpkg: error:
, então talvez seja um erro dpkg
?
Eu tentei substituir a linha os.popen
por os.Popen(["dpkg --get-selections"], stdout=PIPE)
e adicionar from subprocess import Popen, PIPE
, mas acabei de receber um erro:
AttributeError: 'module' object has no attribute 'Popen'
Alguma idéia?