Skip to content

Command line app that executes the submitted code

Notifications You must be signed in to change notification settings

senicko/code-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code runner

Code runner is a go program that takes code as an input and returs the generated output.

Examples

Consider simple Hello, World! app.

package main

import "fmt"

func main() {
  fmt.Println("Hello, World!")
}

To execute it you need to write a following request to the stdin.

For now main.go is an entry file.

{
  "files": [
    {
      "name": "main.go",
      "body": "package main\nimport \"fmt\"\nfunc main(){\nfmt.Println(\"Hello, World!\")\n}"
    }
  ]
}

You should get following response written to stdout.

{
  "stdout": "Hello, World!\n",
  "stderr": "",
  "exitCode": 0
}

You can write something to stdin with stdin field in the config.

{
  "stdin": "blip blip blop blop",
  "files": ...
}

If error is caused by user's submitted code it is returned as a regular response written to stdout.

package main

import "fmt"

func main() {
  fmt.Println"Hello, World!")
  //         ^
  // missing parenthese
}
{
  "stdout": "",
  "stderr": "# command-line-arguments\nfiles/main.go:4:16: syntax error: unexpected jest, expecting comma or )\nfiles/main.go:4:27: newline in string\n",
  "exitCode": 2
}

Errors that occure because of invalid request or internal problems are written to stderr.

Example with incorrect request

Error: invalid character 'a' looking for beginning of value

Building images

docker build -t code-runner/<language> -f ./dockerfiles/<language>/Dockerfile .

About

Command line app that executes the submitted code

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published