Redirect os.system output
Steve Holden
steve at holdenweb.com
Mon Oct 24 09:18:31 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.
>
It looks to me like the line you thought you were typing at the Python
command interpreter actually got snagged by the command processor you
just ran, which presumably is taking its input from the console just
like Python is.
> Ideas?
>
Haven't used subprocess much yet, but I will just mention that this kind
of thing always looks easy in principle and turns out to be surprisingly
gnarly and difficult in practice.
I'm not suggesting you shouldn't continue, but you are going to learn a
*lot* as you proceed. Good luck.
regards
Steve
[...]
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list