Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I want to know that is there any different way to post the code to compiler API for the execution? 

var request = require('request');

var fs=require("fs");

var program = {

    script :"print('hello\nworld')",

    language: "python3",

    versionIndex: "0",

    clientId: "clientID",

    clientSecret:"clientSecret"

};

request({

    url: 'https://api.jdoodle.com/execute',

    method: "POST",

    json: program

},

function (error, response, body) {

    console.log('error:', error);

    console.log('statusCode:', response && response.statusCode);

    console.log('body:', body);

});

The output:

error: null

statusCode: 200

body: { output: '\njdoodle.c:1:7: warning: missing terminating \' character\n print(\'hello\n       ^\njdoodle.c:1:1: error: missing terminating \' c

haracter\n print(\'hello\n ^\njdoodle.c:2:6: warning: missing terminating \' character\n world\')\n      ^\njdoodle.c:2:1: error: missing terminating

 \' character\n world\')\n ^\njdoodle.c:2:1: error: expected \')\' at end of input\n',

  statusCode: 200,

  memory: null,

  cpuTime: null }

1 Answer

0 votes
by (107k points)

Kindly use textArea() so that you can fetch the code and later on, it will automatically convert the code to jDoodle readable format. For your program, kindly use the below code:

script :"print('hello\r\nworld')",

 Want to be a Python expert? Join this Python Training course by Intellipaat to learn more.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...