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

Dick Moores rdm at rcblue.com
Tue Oct 18 22:36:49 CEST 2005


Ah, the line

   dest = open('cmd_help.txt', 'wb')

Thanks, Kent. Yes, I've got it.

Dick

Kent Johnson wrote at 13:23 10/18/2005:
>It makes a file called cmd_help.txt in the current directory. Did you 
>look for that? The file contains the result of asking for help on every 
>command. Kind of cool!
>
>Kent
>
>Dick Moores wrote:
> > 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
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list