How to Create a Web App to Compile and Run Java/C/PHP Code Online?
Asked Answered
I

2

24

Though this is a question with broader scope, I want to write a Online Test Code for my company where people can be given questions to write code in java/php/c etc and the code run and compiles online. I have seen this happening in site like codeacademy, Udacity etc. Just want to understand the architecture behind it. I have searched a lot along the similiar lines a lot on Google but couldnt find a concrete answer. Though after reading bits and pieces here and there i understood that the code is sent to compiler on server and then the results are sent back. Not sure how exactly that happens. Can somebody point me to a starting point of it.

Intension answered 22/9, 2014 at 6:11 Comment(2)
How is Question offtopic, Whats the platform other than Stackoverflow to find answers to such problems? IF there is such a platform please redirect me there.Intension
Great question, imo. It was helpful to me and isn't that the purpose of this site? I totally sympathize with you here as well, there is literally wayy way too many people (particularly on stackoverflow ) that parade around on here all high and mighty down voting, and making ridiculous trivial claims about questions. I think I've literally posted maybe twice on stackoverflow is the past year for this reason, it's really just not worth it anymore, I rather spend and extra day if need be to solve something then feed some of trolls/lowlifes on here.Omeara
K
8

What you can basically have, according to a MVC pattern applied to a web architecture, is something like this:

  • A web application client-side, which allows the user to insert some code, possibly leveraging Javascript for early syntactic check
  • A server endpoint, receiving the inserted code as input from the client

The sequence of operations could be:

  1. Server-side, the input is transformed into the appropriate structure for the target programming language, e.g. a Java class or a C module.
  2. Possibly, more context is defined (e.g. a classpath).
  3. Then, if the language is compiled, the compiler is invoked (e.g. javac or gcc). This can happen in several ways, e.g. exec in C or Runtime.getRuntime().exec in Java. Otherwise the code can be deployed on a server or some simulators can be run and passed the code.
  4. Subsequently, the code is executed and output is intercepted (e.g. by directioning the console output to a file or just leveraging the target language infrastructure, like in this example). The execution can happen through command line (e.g. java) or via other tools (e.g. curl for running a deployed php code as it was a client browser accessing it)
  5. Last step for the server is to send back the intercepted output to the client in a readable format, e.g. HTML. As an alternative, if you used Java, you could go for Applet, which doesn't change the basic architecture.

However, more in general, the point is that compilers and interpreters are base software. They are not intended for general users, which can easily live with the Operating System only. Therefore, "on line compiling", at the best of my knowledge, is something different from "posting code, letting it execute on a server, and visualizing the answer". Online compiling would mean distributing the responsibility of compiling across the network, which does make sense, but, in my opinion, it is not meant to use for demonstrative purpose (like you are mentioning).

Kamp answered 22/9, 2014 at 6:28 Comment(1)
do you have any useful books or playlist ?Illyricum
N
2

I used domjudge for my company and customized it for my need.

PHP code is very well written. It is very modular and simple to adapt to your requirements.

Nation answered 22/9, 2014 at 6:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.