[pygtk] os.popen to gtk.TextView

Steve McClure smcclure at racemi.com
Thu Mar 24 07:16:15 WST 2005


On Wed, 2005-03-23 at 15:27, Marcus Habermehl wrote:
> Hi.
> 
> I want to write the output of os.popen('command') to a gtk.TextView.
> 
> But I don't know how. :(
> 
> If I use
> 
> for line in os.popen('command').readlines():
>     textview.insert_at_cursor(line)
> 
> I must wait untils 'command' has finished.
> 
> Is there a better way? Is it not possible to wrote the output directly 
> to a gtk.TextView?
> 
> I have found some documentation about pipes or related things. But 
> because my english isn't very good I doesn't understand it realy.
> 
> Have anyone a hint for me?

Try looking at os.popen3

You can do something like

stdin, stdout, stderr = os.popen3(command)
while not done:
	try:
		outputstr = stdout.readline()
		if outputstr == '':
			done = 1
		else:
			# do something with textview and outputstr
	except (IOError):
		# ignore interrupted system calls here otherwise
		done = 1

stdin.close()
stdout.close()
stderr.close()

> 
> regards
> Marcus
> 
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
-- 
Steve McClure						Racemi
email: smcclure at racemi.com				75 5th St NE
voice: 404-892-5850					Suite 333
fax: 404-892-7215					Atlanta, GA 30308
							http://www.racemi.com



More information about the pygtk mailing list