Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hsjoihs
Last active June 17, 2019 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsjoihs/2038535a47b853587e1a261678595ed9 to your computer and use it in GitHub Desktop.
Save hsjoihs/2038535a47b853587e1a261678595ed9 to your computer and use it in GitHub Desktop.
POST to wandbox
#include <iostream>
int main() { int x = 0; std::cout << "hoge" << std::endl; }
import { readFileSync } from 'fs';
const request = require('request');
function emitRes(res) {
console.log("\n----compiler----------------");
console.log(res.compiler_message);
console.log("\n----program-----------------");
console.log(res.program_message);
console.log("\n----exit code---------------");
console.log(res.status);
}
{
let obj = {
"options": "warning,gnu++1y",
"compiler": "gcc-head",
"compiler-option-raw": "-Dx=hogefuga\n-O3"
};
obj.code = readFileSync('/dev/stdin', 'utf8');
const headers = {
'Content-type': 'application/json'
};
const dataString = JSON.stringify(obj);
const options = {
url: 'https://wandbox.org/api/compile.json',
method: 'POST',
headers: headers,
body: dataString
};
request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
emitRes(JSON.parse(body));
}
});
}
foo:
cat a.cpp | node -r esm main.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment