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 use开发者_JS百科r the output of the file.
How can i do that???Kernel.system may the command that you are looking for: it calls a system process. For example:
if (system("gcc ..."))
@output_to_show = %x['./compiled']
end
Assuming that your server is in Linux/UNIX, it would be good to separate the compile&execute process from the website server in order to reduce the security risks (by creating a new user just for this purpose). Or can you trust the content of the cpp-Files?
精彩评论