Library for interactive command line interface?

Nov 29, 2009 at 11:11am
Hi,

I'm looking for a way to control my program interactively through a command line interface. Similar to controlling linux through the shell or python through its scripting interface.

Is there a library that implements an interactive command-line interpreter? For those of you who have some experience with python: I'm looking for the C-counterpart of the python module cmd.
Nov 29, 2009 at 11:41am
You mean like curses?
Nov 29, 2009 at 12:31pm
No, not like curses. I want to have a non-graphic user interface. For example, imagine a painting program. With a purely graphical user interface one could select the color of the pen via pressing a button. But I want a purely text-based interface, where you would set the color with a text command in an interactive command line like: "set pencolor red"
Nov 29, 2009 at 12:46pm
stdio ?
Nov 29, 2009 at 1:18pm
I'd like to have something much more high-level: define some commands and parameters, pass them to the magic command line interpreter and define some functions to call when the user types those commands. This is kinda like what the cmd module in python offers.
Nov 29, 2009 at 1:28pm
You could call Python from C++.
Nov 29, 2009 at 1:45pm
You could call Python from C++

You can do that? :S
Nov 29, 2009 at 2:02pm
You could call Python from C++.


Yes I could do that, but that would be overkill, if I just want to use it for the interactive command line.

If there's really no such library for c, I'm going to write one by myself.
Nov 29, 2009 at 2:08pm
Well, what you want is rather specific. You could also try reading the Python documentation. Maybe it says what that module is based on.

You can do that? :S
It's called "embedding". All you do is dynamically link to the interpreter and send code and/or data to it. It's also possible to call C/++ functions from Python. That's called "extending".
Nov 29, 2009 at 2:24pm
Well, what you want is rather specific. You could also try reading the Python documentation. Maybe it says what that module is based on.


Is is really that specific? Whenever you have a program that is controlled by a loop that waits for a command, then executes a command specific function, prints the results, and then waits for the next command a library like that one would be helpful. Usually when you write such programs, the commands are single characters. But sometimes more complex commands might be necessary.
Nov 29, 2009 at 2:27pm
I still think that stdio does that...
Nov 29, 2009 at 2:36pm
I still think that stdio does that...


I think with stdio you can only process input and output of streams (text streams for example). I will definitely need it to read in the command strings. But I think there's no way to use stdio for going the next steps, i.e. parsing the command strings, and automatically calling functions in my program corresponding to the commands
Nov 29, 2009 at 3:00pm
Command line input is a stream, parsing input isn't difficult.
Maybe I don't fully understand what you are trying to do, can you post an example in Python?
Topic archived. No new replies allowed.