如何创建一个Web应用程序编译和运行Java / C / PHP code网? [英] How to Create a Web App to Compile and Run Java/C/PHP Code Online?

查看:119
本文介绍了如何创建一个Web应用程序编译和运行Java / C / PHP code网?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这是与范围更广的问题,我想写我公司在线测试code,人们可以给出问题写在Java / PHP / C等和$ C $ code C运行和在线编译。我已经看到这种情况出现在网站,如codeacademy,Udacity等只是想了解它背后的架构。我曾沿着similiar线搜索了很多关于谷歌很多,但无法找到一个具体的答案。虽然在这里和那里读书的点点滴滴后,我明白,code发送到编译器的服务器,然后将结果发送回。不知道究竟是如何发生这种情况。有人能指出我到它的出发点。

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.

推荐答案

你基本上可以有哪些,根据适用于网络体系结构的MVC模式,是这样的:

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


  • Web应用程序客户端,它允许用户插入一些code,
    可能利用JavaScript进行早期检查语法

  • 的服务器端点,
    接到插入code作为输入从客户端

操作的顺序可以是:


  1. 服务器端,该输入被变换成用于目标的编程语言,例如适当的结构一个Java类或C模块。

  2. 也许,更多的上下文定义(如类路径)。

  3. 之后,如果语言编译,编译器调用(例如javac的或GCC)。这可以以几种方式发生,例如EXEC在C或调用Runtime.getRuntime()。EXEC在Java中。否则,code可以部署在服务器上或某些模拟器可以运行,并通过了code。

  4. 接着,code为执行和输出被截取(例如由控制台输出用法后到文件或只是利用目标语言的基础设施,如在<一href=\"http://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program\">this例如)。执行可以通过命令行(例如,Java),或通过其他工具发生(如卷曲用于运行PHP部署code,因为它是一个客户端浏览器访问它)

  5. 为服务器最后一步是发回截取输出到客户端以可读格式,例如HTML。作为一种替代方法,如果你使用的Java,你可以去小程序,这不会改变基本架构。

  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.

然而,更一般地,点是,编译器和除preters是基本软件。他们不是用于一般用户来说,这很容易,只有操作系统居住。因此,上线编译,以我所知,是一些不同于发帖code,让它执行一个服务器上,并可视化的答案。在线编译意味着分布在网络上,这有一定道理编译的责任,但是,在我看来,这并不意味着用于示范的目的(像你提)。

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).

这篇关于如何创建一个Web应用程序编译和运行Java / C / PHP code网?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆