IdeaMonk

thoughts, ideas, code and other things...

Saturday, February 13, 2010

Sudo weirdness with QProcess and Python interpreter

Working with PyQt4, trying to do some cheap hacks to get console output in the UI, I stumbled upon QProcess and landed in a weird situation -
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4 import QtCore
>>> process = QtCore.QProcess()
>>> process.start("sudo ls")
>>> [sudo] password for ideamonk: mk48d

Notice the "mk48d" there. Well that's not my password, but they are some of the keys that somehow got filtered out and got printed by the interpreter. Indeed this situation wont come up in real life, but its a point to ponder upon as to why do both the processes - sudo and python interpreter split the user input amongst each other.



anyways laters!

Labels:

1 Comments:

At February 14, 2010 at 3:49 PM , Blogger Abhishek Mishra said...

So I tried some stdout redirection magic to test flush -

Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4 import QtCore
>>> process = QtCore.QProcess()
>>> import sys
>>> class Foo():
...     def write(self,text):
...             # whenever this process puts something in stdout
...             print "###", text
...     def flush(self):
...             # whenever this process flushes
...             print "+++ flushed"
...
>>> f = Foo()
>>> sys.stdout = f
>>> process.start("sudo ls")
>>> [sudo] password for ideamonk: kj


Ah still nothing got caught by the io redirects set out to catch flushes for this program. Interestingly this happens only in the interactive interpreter and not when I ask the interpreter to execute a script with same code.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home