GithubHelp home page GithubHelp logo

glot-code-runner's Introduction

glot-code-runner

THIS REPO IS DEPRECATED AND HAS BEEN REPLACED BY code-runner

Overview

glot-code-runner is a command line application that reads code as a json payload from stdin – compiles and runs the code – and writes the result as json to stdout.

Prerequisites

glot-code-runner requires that the compiler / interpreter for the languages you want to run is installed and is in PATH.

Supported languages

  • assembly
  • ats
  • bash
  • c
  • clojure
  • cobol
  • coffeescript
  • cpp
  • csharp
  • d
  • elixir
  • elm
  • erlang
  • fsharp
  • golang
  • groovy
  • haskell
  • idris
  • java
  • javascript
  • julia
  • lua
  • nim
  • ocaml
  • perl
  • perl6
  • php
  • python
  • ruby
  • rust
  • scala
  • swift

Input (stdin)

The input is required to be a json object containing the properties language and files. language must be a lowecase string matching one of the supported languages. files must be an array with at least one object containing the properties name and content. name is the name of the file and can include forward slashes to create the file in a subdirectory relative to the base directory. All files are written into the same base directory under the OS's temp dir.

In addition, one may optionally provide the stdin and command properties to provide stdin data to the running code and to run the code with a custom command. See examples below.

Output (stdout)

The output is a json object containing the properties stdout, stderr and error. stdout and stderr is captured from the output of the ran code. error is popuplated if there is a compiler / interpreter error. Note that glot-code-runner will exit with a non-zero code if invalid input is given or if the files cannot be written to disk (permissions, disk space, etc). No json will be written to stdout in those cases. Otherwise the exit code is 0.

Examples

Simple example

Input
{
  "language": "python",
  "files": [
    {
      "name": "main.py",
      "content": "print(42)"
    }
  ]
}
Output
{
  "stdout": "42\n",
  "stderr": "",
  "error": ""
}

Read from stdin

Input
{
  "language": "python",
  "stdin": "42",
  "files": [
    {
      "name": "main.py",
      "content": "print(input('Number from stdin: '))"
    }
  ]
}
Output
{
  "stdout": "Number from stdin: 42\n",
  "stderr": "",
  "error": ""
}

Custom run command

Input
{
  "language": "bash",
  "command": "bash main.sh 42",
  "files": [
    {
      "name": "main.sh",
      "content": "echo Number from arg: $1"
    }
  ]
}
Output
{
  "stdout": "Number from arg: 42\n",
  "stderr": "",
  "error": ""
}

glot-code-runner's People

Contributors

aloisdg avatar maddyonline avatar mattoates avatar nishtahir avatar oprypin avatar prasmussen avatar rightfold avatar steinwaywhw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

glot-code-runner's Issues

Changing relative import to absolute import

Currently many imports used are relative. This prevents from using tools like go get. Of course, one can build the binary by using go build github.com/prasmussen/glot-code-runner/runner.go. But for working on fork, it seems it would be useful if imports are fully qualified. Is there a reason for not preferring this style?

java String.intern() is wrong

I create a snippet about java and this is my code.
class Main { public static void main(String[] args) { System.out.println(System.getProperty("java.version")); System.out.println(System.getProperty("java.vendor")); System.out.println(System.getProperty("java.vendor.url")); System.out.println(System.getProperty("java.home")); System.out.println(System.getProperty("java.vm.specification.version")); System.out.println(System.getProperty("java.vm.version")); System.out.println(System.getProperty("java.vm.vendor")); System.out.println(System.getProperty("java.vm.name")); String s1 = new StringBuilder("go").append("od").toString(); System.out.println(s1.intern() == s1); String s2 = new StringBuilder("ja").append("va").toString(); System.out.println(s2.intern() == s2); } }
the output is:
image
but in my ide, the output is :
image
my ide's output is right base the java specification and why the glot is wrong ?

Arbitrarily code execute

This program doesn't limit the execution of command, we can run arbitrarily command on this runner.

payload:

{
  "language": "python",
  "files": [
    {
      "name": "main.py",
      "content": "import os\nos.system('touch /tmp/pwned')"
    }
  ]
}

output:

# ./runner
{
  "language": "python",
  "files": [
    {
      "name": "main.py",
      "content": "import os\nos.system('touch /tmp/pwned')"
    }
  ]
}
{"stdout":"","stderr":"","error":""}
# ls |grep pwn
pwned

If this program run on a website, it will cause remote command execution.

For example
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.