[Tutor] "a cute recipe for getting the help command text"

Dick Moores rdm at rcblue.com
Tue Oct 18 22:00:12 CEST 2005


Found this in comp.lang.python. The Google link is 
<http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?dmode=source>

=================================
import subprocess as subp

p = subp.Popen("cmd.exe /X/D/F:ON", stdin=subp.PIPE,
             stdout=subp.PIPE, stderr=subp.STDOUT)
flag = "(@@@@@@}"
print >>p.stdin, "PROMPT", flag
print >>p.stdin, "HELP"
print >>p.stdin, "EXIT"
text = p.stdout.read()
p.wait()
helptext = text[text.index(flag + 'HELP') + len(flag) + 4 :
              text.index(flag + 'EXIT')]
words = [line.split(None, 1)[0]
       for line in helptext.split('\n')
       if line.strip()]
commands = [word for word in words if word.isupper()]

dest = open('cmd_help.txt', 'wb')
p = subp.Popen("cmd.exe /X/D/F:ON", stdin=subp.PIPE,
             stdout=dest, stderr=subp.STDOUT)
print >>p.stdin, "PROMPT (@@@@@@@@)"
print >>p.stdin, "HELP"
for command in commands:
  print >>p.stdin, "HELP", command
print >>p.stdin, "EXIT"
p.wait()
dest.close()
=================end of script=============

When I run this I get no text, but just a series of cmd.exe windows 
entitled HELP <command>. How do I get any text?

Thanks,

Dick Moores



More information about the Tutor mailing list