For # 1:
Because you have not process the standard pipe and output, so the print out of the command will just print there in the screen. When you want to process the standard pipe, you need both process the stdout and stderr. Otherwise you actually cannot capture the standard pipe. When you specify a standard pipe, you should handle the standard error print out at the same time.
It's more like this below, if you have a function under the module named "func_my.py":
def func_my():
print "Hello"
return "World"
if __name__ == "__main__":
func_my()
When you call this function, if you don't process the console output, the string "hello" will be directly show in the console output.
p = subprocess.Popen(["python", "func_my.py"], stdout=subprocess.PIPE)
This will always print the "hello".
For #2: You do capture the standard output and error put, but you have made a mistake. You have put all the pipe to both stdout and stderr. The right way should bwlow:
p = subprocess.Popen(["tshark", "-D"], stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
p.stderr.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'read'
p.stdout.read()
"WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-UBTaGc/pkcs11: No such file or directory\ntshark: There are no interfaces on which a capture can be done\n"
Hope will hep you!