[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 

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()
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"
=================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?


Dick Moores

More information about the Tutor mailing list