tags:

views:

81

answers:

3

Hello,

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 be 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

A: 

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.

Peter G.
-1: Really not relevant here.
rubenvb
I see I misunderstood the question. I didn't read carefully and thought he wanted to add an interactive prompt to an already running application. If more think my answer is totally irrelevant I will delete it.
Peter G.
@Peter G, indeed it isn't exactly what I had in mind, but I like the trick. If I understand correctly, this way I don't need GNU Readline - the telnet client will supply most of the readline functionality and I will just need to parse the resulting string. Am I correct?
FireAphis
GNU readline is completely orthogonal to telnet and to parsing. It provides an editable command line prompt including a history. Telnet provides a way to open and use a TCP connection to transfer text to and from your application. There might be telnet clients which provide or use readline functionality themselves.
Peter G.
+2  A: 

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

Lou Franco
Thanks, but I was hoping there is something that allows me actually to define the commands so the library will handle all the parsing.
FireAphis
+1  A: 

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

ShaderOp
This is an over-kill in my case, but it's nice to be aware of the option. Maybe I'll do it just because it's an interesting experiment :)
FireAphis
Sorry it wasn't of much use to you, but yes, it is a an interesting experiment that can turn very addictive :) Good luck with your search.
ShaderOp