I created a man page for my C++ application and I would like to show it to the user when a particular flag is specified in the command line. Is system("man myapplication")
the only way to do this, or are there any better options?
Asked
Active
Viewed 196 times
0

GOTO 0
- 42,323
- 22
- 125
- 158
-
Do you want to continue after displaying the man page? – Kerrek SB Oct 06 '13 at 20:48
-
@KerrekSB no, just return a value from `main`. – GOTO 0 Oct 06 '13 at 20:50
-
In that case you could do `execl("/usr/bin/man", "/usr/bin/man", "myapplication", NULL)`, but as msw says, that requires all the dependencies to be met. – Kerrek SB Oct 06 '13 at 21:47
1 Answers
0
I'd probably take the nroff (text) output of man
and stick it either in the code as one huge string or in a separate file depending on how many pieces the program installs with.
Calling system("man")
requires a lot of dependencies which is the last thing your unfortunate user wants to deal with after typing my_program --long-help
. It would work just fine in many cases, but when it didn't you'd lose an important feature of your program and have to report the rather silly "sorry: no long help available".
This would also increase portability to systems that never had a man
program.

msw
- 42,753
- 9
- 87
- 112