Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/10/2011, 18:25
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Python y Bash

Código Python:
Ver original
  1. #coding: cp1252
  2. import pygtk
  3. from subprocess import Popen, PIPE
  4. import gtk
  5.  
  6. pygtk.require('2.0')
  7.  
  8. class MyApp():
  9.    
  10.     def onClick(self, widget, data=None):
  11.         process = Popen(["dir"], shell=True, stdout=PIPE)
  12.        
  13.         text = process.stdout.read()
  14.         text = unicode(text, "cp1252")
  15.        
  16.         buffer = gtk.TextBuffer()
  17.         buffer.set_text(text)
  18.        
  19.         self.textView.set_buffer(buffer)
  20.    
  21.     def __init__(self):
  22.         self.window = gtk.Window()
  23.         self.vbox = gtk.VBox()
  24.         self.button = gtk.Button("dir")
  25.         self.textView = gtk.TextView()
  26.        
  27.         self.window.set_border_width(10)
  28.         self.vbox.add(self.textView)
  29.         self.vbox.add(self.button)
  30.         self.window.add(self.vbox)
  31.        
  32.         self.window.connect("destroy", gtk.main_quit)
  33.         self.button.connect("clicked", self.onClick, None)
  34.        
  35.         self.window.show_all()
  36.        
  37. if __name__ == "__main__":
  38.     app = MyApp()
  39.     gtk.main()
Este es un ejemplo usando PyGTK y subprocess.

Estoy usando windows + cp1252 de encoding para el archivo.