You can grab the whole output of a command with check_output
. Furthermore, using a shell is not necessary and might even make your application vulnerable to a shell injection attack and is strongly discouraged.
import subprocess
pagename = 'man'
manpage = subprocess.check_output(['man', pagename])
Note that using man
will give you output formatted for a terminal. If you want to have it formatted differently, you'll have to
- call
man -w <name>
to get the location of the manpage,
- probably decompress the manual page,
- feed it to
groff
using the -T
option to select the type of output you want.
When calling groff
, don't forget to load the correct macro's.
On FreeBSD I tend use groff -Tlatin1 -mandoc <file>
to get text output.