subprocess.communicate messes things up

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Sep 7 22:49:12 EDT 2007


En Fri, 07 Sep 2007 22:51:34 -0300, <KingShivan at gmail.com> escribi�:

> problem is that the first time I press a key, it works, but after it
> just print the keys I press, the annoying line being the one with
> communicate, any idea of what is happening ?
>
> 	child1 = subprocess.Popen("/usr/bin/mplayer -slave -quiet -
> idle",stdin=subprocess.PIPE,stdout=FNULL,stderr=FNULL,shell=True)
> 	while 1:
> 		ch=getkey()
> 		name=os.listdir("/home/shivan/"+ch)
> 		file_to_load = "/home/shivan/"+ch+"/"+name[0]
> 		print "loadfile "+file_to_load
> 		output, errors = child1.communicate("loadfile "+file_to_load+" \n")

communicate sends its input and waits until the process finishes,  
collecting all output. So it's not adequate for your needs.
You should write directly to child1.stdin: child1.stdin.write("loadfile  
"+file_to_load+" \n")

-- 
Gabriel Genellina




More information about the Python-list mailing list