Usually, when you try to invoke the command line using the actual command, it is easier to just call it with the "/ k" parameter, rather than passing commands through stdin. That is, just name "cmd.exe / k dir". For instance,
from os import *
a = popen("cmd /k dir")
print (a.read())
The code below does the same thing, although you are missing a line to manipulate, since it directly outputs the output:
from subprocess import *
Popen("cmd /k dir")
Brian source
share