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???
views:
20answers:
1
+1
A:
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?
giraff
2010-07-30 21:31:08
@giraff :-"You may want to run theses processes under another user-id, just to be sure they don't overwrite some of your hard-gained code files etc. ..."....I could not understand that. Can you alaborate a bit.
Silver Spoon
2010-07-30 21:44:56
@giraff :- Thanks for the help.
Silver Spoon
2010-07-31 05:45:31
@giraff :- Could you explain the %x['./compiled'] part in your code. How can i get the output/ errors in the compilation process
Silver Spoon
2010-07-31 07:08:42
While system() only returns the success (or not) of the command, %x[] returns the outpout of stdout (see linked article: http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html).
giraff
2010-07-31 09:17:26