running linux ccommands in a C program
for the sake of arguement, let's say I was writing a C or C++ gui program. In this program I wish to have the user supply arguements which I would then use to run a command.
eg A front end to lame So I want them to select a bitrate and filename then I want to execute the command lame -b bitrate filename.mp3 This is just an example, so if I have the lame syntax wrong, don't worry. I was just curious what I had to do to execute linux commands from within a C/C++ program. Thanks, |
Use system() or exec() function.
Code:
main(){ |
you might also want to looking into the popen. It opens a stream to a command, meaning your program will receive the output from the command instead of it being sent straight to stdout.
|
thanks a lot! Esp Nix, that was very helpful
|
I think if you will use System(), it directly it will shift the control to that command, so if you want to create a child process that will execute your command and your original application will continue normally you can use fork() and exec(). see "man fork" for details.
|
All times are GMT -5. The time now is 12:39 PM. |