Redirect os.system output

Paul Dale pd at traxon.com
Tue Oct 25 03:30:16 EDT 2005


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