开发者

External commands in a controller

开发者 https://www.devze.com 2023-01-09 21:02 出处:网络
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 u

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

精彩评论

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

关注公众号