xshanow
V2EX  ›  问与答

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

  •  1
     
  •   xshanow · Apr 19, 2018 · 8756 views
    This topic created in 2971 days ago, the information mentioned may be changed or developed.

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

    这样:

    https://tool.lu/mine

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

    demo 的地址是: https://www.justice.plus
    honist
        11
    honist  
       Apr 19, 2018
    star 了楼上 有空研究一下
    chinvo
        12
    chinvo  
       Apr 19, 2018
    和 OJ 的原理一样,后端沙盒运行,捕获输入输出
    dobelee
        13
    dobelee  
       Apr 19, 2018 via Android
    后端的虚拟机编译执行一下就 ok 了。
    kaneg
        14
    kaneg  
       Apr 19, 2018 via iPhone
    云端跑个 docker 就可以
    xshanow
        15
    xshanow  
    OP
       Apr 28, 2018
    没想到这么多人收藏了 。
    我主要研究的是 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,没测试。

    以上。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2820 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 69ms · UTC 09:57 · PVG 17:57 · LAX 02:57 · JFK 05:57
    ♥ Do have faith in what you're doing.