Redirect os.system output

jas codecraig at gmail.com
Tue Oct 25 07:30:04 EDT 2005


Paul,
   I did ceck out the PExpect, however, I thought it was not ported for
Windows.  Did you find a ported version?  If not, what did you have to
do to be able to use it?

Thanks

Paul Dale wrote:
> You might want to try python expect which gives you a very simple and
> scriptable interface to a process.
>
> http://pexpect.sourceforge.net/
>
> I've been using it on windows to automate a few things.
>
> Cheers,
>
> Paul
>
> jas wrote:
>
> >Kent,
> >  Yes, your example does work.  So did os.popen...however, the problem
> >is specific to "cmd.exe".
> >   Have you tried that yet?
> >
> >Thanks!
> >
> >Kent Johnson wrote:
> >
> >
> >>jas wrote:
> >>
> >>
> >>>Ok, I tried this...
> >>>
> >>>C:\>python
> >>>Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
> >>>on win32
> >>>Type "help", "copyright", "credits" or "license" for more information.
> >>>
> >>>
> >>>
> >>>>>>import subprocess as sp
> >>>>>>p = sp.Popen("cmd", stdout=sp.PIPE)
> >>>>>>
> >>>>>>result = p.communicate("ipconfig")
> >>>>>>
> >>>>>>
> >>>'result' is not recognized as an internal or external command,
> >>>operable program or batch file.
> >>>
> >>>
> >>>
> >>>basically I was opening to send the "ipconfig" command to cmd.exe and
> >>>store the result in the "result" variable.  But you can see there was
> >>>an error with result.
> >>>
> >>>
> >>This works for me:
> >>import subprocess as sp
> >>p = sp.Popen("ipconfig", stdout=sp.PIPE)
> >>result = p.communicate()[0]
> >>print result
> >>
> >>Kent
> >>    
> >>
> >
> >  
> >




More information about the Python-list mailing list