Redirect os.system output
Kent Johnson
kent37 at tds.net
Mon Oct 24 12:07:41 EDT 2005
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