command.getoutput()

Mark McEahern marklists at mceahern.com
Thu Feb 27 14:34:54 CET 2003


[Peter Wu]
> Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import commands
> >>> commands.getoutput('ver')
> "'{' is not recognized as an internal or external
> command,\noperable program or batch file."
> >>> commands.getoutput("ver")
> "'{' is not recognized as an internal or external
> command,\noperable program or batch file."
> >>>
>
>
> What's the problem here? Thanks.

Read the top-level comments in commands.py:

# Module 'commands'
#
# Various tools for executing commands and looking at their output and
status.
#
# NB This only works (and is only relevant) for UNIX.

IMHO, that should be in the __doc__ string, but I'm too lazy to bother
filing a bug report about that.

Depending on what you actually need, you may get by with plumbing the
available methods of either os or sys.  Or, you could write your own
commands.getoutput():

>>> import os
>>> f = os.popen('ver')
>>> s = f.read()
>>> s
'\nMicrosoft Windows XP [Version 5.1.2600]\n'
>>>

Cheers,

// m

-






More information about the Python-list mailing list