Redirect os.system output

jas codecraig at gmail.com
Mon Oct 24 08:33:15 EDT 2005


I see that, although I don't totall grasp the code.  However, I am
looking to basically emulate a command prompt.  i.e. everything u see
in the windows command prompt should be displayed back in python.

How can I do it without files?

Kent Johnson wrote:
> jas wrote:
> > Any other ideas? or examples of using subprocess to do what I was
> > asking?
>
> Actually I thought I was giving an example of what you were asking:
> - on windows
> - send a series of commands to a command process
> - capture the result to a variable
>
> The example I referenced sends a series of HELP commands to cmd.exe, captures the output of the commands and saves it to a file.
>
> What did I miss?
>
> Kent
>
> >
> >
> > Kent Johnson wrote:
> >
> >>jas wrote:
> >>
> >>>I would like to redirect the output from os.system to a variable, but
> >>>am having trouble.  I tried using os.popen(..).read() ...but that
> >>>doesn't give me exactly what i want.
> >>
> >>Here is an example using subprocess:
> >>http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en&
> >>
> >>Kent
> >>
> >>
> >>>..this is windows by the way.
> >>>
> >>>For example:
> >>>tmp = os.popen("hostname").read()
> >>>
> >>>...works as expected.
> >>>
> >>>however,
> >>>
> >>>tmp = os.popen("cmd").read()
> >>>...i would like to have access to the cmd process...i.e. enter commands
> >>>like a normal command line. os.system() allows this, but i dont want
> >>>output to the screen..i wanna store it to a variable.  then send
> >>>content of variable elsewhere,  receive more input and submit it.
> >>>almost emulate the windows command prompt.
> >>>
> >>>any ideas?
> >>>
> > 
> >




More information about the Python-list mailing list