V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
xshanow
V2EX  ›  问与答

在线运行代码怎么实现的?

  •  1
     
  •   xshanow · 2018-04-19 11:23:01 +08:00 · 7733 次点击
    这是一个创建于 2189 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如图: 各位大神,有知道这个怎么实现的吗?

    这样:

    https://tool.lu/mine

    15 条回复    2018-04-28 17:57:42 +08:00
    crazybug
        1
    crazybug  
       2018-04-19 11:37:43 +08:00
    提交的代码在服务器端执行完在返回到浏览器!
    Luckyray
        2
    Luckyray  
       2018-04-19 11:43:29 +08:00
    应该是 1 楼的办法吧,总不能全用 js 写一套解释器,那也太复杂了。
    input2output
        3
    input2output  
       2018-04-19 11:53:12 +08:00
    在云端 sandbox 里运行的;
    current
        4
    current  
       2018-04-19 12:13:10 +08:00
    hxndg
        5
    hxndg  
       2018-04-19 13:02:51 +08:00
    @input2output
    哈哈哈,不过一般都是在沙盒做的,基本不可能
    tommyZZM
        6
    tommyZZM  
       2018-04-19 15:28:02 +08:00
    服务端运行,然后把 stdin/stdout/stderr 接到前端输入或者显示吧
    kevindu
        7
    kevindu  
       2018-04-19 15:57:23 +08:00
    wshcdr
        8
    wshcdr  
       2018-04-19 17:01:44 +08:00
    比较感兴趣,MARK 一记
    LeungJZ
        9
    LeungJZ  
       2018-04-19 17:07:23 +08:00
    感兴趣,mark 一下。
    holyghost
        10
    holyghost  
       2018-04-19 17:13:32 +08:00   ❤️ 2
    实际上就是一个 sandbox,刚好我之前用 namespace 和 cgroup 实现了一个: https://github.com/justice-oj/sandbox

    demo 的地址是: https://www.justice.plus
    honist
        11
    honist  
       2018-04-19 19:31:40 +08:00
    star 了楼上 有空研究一下
    chinvo
        12
    chinvo  
       2018-04-19 19:35:27 +08:00
    和 OJ 的原理一样,后端沙盒运行,捕获输入输出
    dobelee
        13
    dobelee  
       2018-04-19 19:36:49 +08:00 via Android
    后端的虚拟机编译执行一下就 ok 了。
    kaneg
        14
    kaneg  
       2018-04-19 20:34:55 +08:00 via iPhone
    云端跑个 docker 就可以
    xshanow
        15
    xshanow  
    OP
       2018-04-28 17:57:42 +08:00
    没想到这么多人收藏了 。
    我主要研究的是 java,c#,c++的,总结以下吧
    [成功]Java 代码中运行 java 代码,使用 Java-Runtime-Compiler 这个库,好使。https://github.com/OpenHFT/Java-Runtime-Compiler
    [成功]C#环境中有 CSharpCodeProvider\CPPCodeProvider..支持 C#和 VB,不知道啥原因 C++的不支持。
    [未知]linux 下,C++可以使用 libdcompile,https://github.com/Fadis/libdcompile,没测试。

    以上。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   960 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 21:32 · PVG 05:32 · LAX 14:32 · JFK 17:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.