开发者

Simple interactive prompt in C++

I work on an application that usually runs unattended. Now I need to add to it something like an interactive prompt. In the interactive mode the operator will be able to give simple commands to the application - nothing fancy, simple commands like start and stop. Parametrized commands (e.g. repeat 10) and commands history could b开发者_JS百科e nice too.

Do you know, by chance, any library that helps with such tasks. I've been thinking about something that works like boost::program_options or gflags but for an interactive prompt and not for command line parameters. Any ideas?

Thanks


Readline is one the best known libraries for this

http://tiswww.case.edu/php/chet/readline/rltop.html

It is covered by GPL, so it is only possible to use in GPL-compatible programs.

I did a quick search for alternatives, and found this:

http://github.com/antirez/linenoise


I'm not sure if the following is a reasonable amount of work for what you're trying to do, but Python has a very nice Command Line Interface (CLI) building library called cmd2. If it's possible to expose the relevant parts of your apps to Python using SWIG or CTypes, then doing the rest should be easy.

Here's a nice video presentation about cmd2:

PyCon 2010:Easy command-line applications with cmd and cmd2

HTH


One possibilty is to open a TCP port and accept messages in text format. Then you can telnet to that port and issue simple commands.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜