开发者

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 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜