Redirect os.system output

Paul Dale pd at traxon.com
Tue Oct 25 16:05:18 CEST 2005


pexpect is POSIX compliant and works under Cygwin. I haven't tried it 
under pythonw.

Just install cgywin (including python) then follow the standard 
instructions for pexpect.

There was one small trick I had to do to get cygwin working totally 
properly on my machine which was run a rebaseall.

Rebaseall sets the memory addresses for the DLLs or something like that.

However, there is a slight problem. The rebaseall runs inside cygwin and 
uses one of the DLLs. To get around this I change the rebaseall script 
to write it's command to a text file and then  run those commands in a 
DOS cmd shell. After that everything has worked without problem.


Good luck,

Paul

jas wrote:

>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