Reputation: 3986
I am attempting to make a program in C which presents a GUI and allows the user to select from a list of applications, which to install on the computer. I can manage the gui, but I've never been taught how to actually issue command line commands.
I know with bash its just apt-get install firefox
for example, but how do I do such a thing with C? i.e. on click, the program runs 'apt-get install
The other problem is I'm not familiar with the proper name for this interaction, so it is hard to search.
Thanks for the help
Upvotes: 1
Views: 648
Reputation: 342363
If using C is not a must, you can try coding in Python(Perl). You will greatly reduce development time, and you can use GUI modules like tkinter(Python) or Tk(Perl) etc that are easy to use. you will have your GUI up in no time.
Upvotes: -1
Reputation: 20842
If you use the traditional C standard lib, you can choose from:
popen()
- Opens a process with stdio IO streams to read/write to the processsystem()
- Executes a process with same IO streams as parentor:
fork()
+ execl()
(or exec variants) which is essentially how system()
is implemented.Try the man pages on all of these.
Also, order "Advanced Programming in the UNIX Environment" by W. Richard Stevens
Upvotes: 6
Reputation: 490128
The portable way to do this is with system()
. The way that's less portable, but more flexible would be to use fork()
followed by exec()
. There is also popen, if you need/want to communicate with the child via its stdin
or stdout
(e.g., if you want to capture its output and display it in a window).
Upvotes: 0
Reputation: 40309
You are attempting to (1) do command line parsing and (2) perform an installation of software. You should know that apt-get is a significant undertaking.
Upvotes: 0
Reputation: 15734
You could see how other people do it. Looks like you're trying to create something similar to Synaptic, you may check in their source.
Upvotes: 0