External commands in a controller

I have various files of extensions .cpp stored on the server. When
user clicks on the compile button, I should run gcc command passing
the absolute path of the file to gcc compiler and then show the user
the output of the file.
How can i do that???

Jatin Kumar wrote:

I have various files of extensions .cpp stored on the server. When
user clicks on the compile button, I should run gcc command passing
the absolute path of the file to gcc compiler and then show the user
the output of the file.
How can i do that???

A silly contrived example:

user_controller.rb

The above dummy code will only list the files in the directory, which
is something i don't really want. I want to individually run all these
files with gcc compiler and then show the user the output/ errors in
the process to the user, in front of each file. Now can you help me???