Python subprocess command (javac "Main.java") is not working on production
i am trying to compile java file from python(django). when i run my code on local sever then my java file compiled sucessfully but when i upload the files on heroku,Javac not found error showing
def method1(request):
code=request.data.get('code')
len1=request.data.get('len')
if os.path.isfile("Main.java"):
os.remove("Main.java")
f = open("Main.java", "x")
f.write(code)
f.close()
file = 'Main.java'
# codes[compile(file,len1)]
std=""
try:
output = subprocess.check_output(
"javac "+file, stderr=subprocess.STDOUT, shell=True, timeout=3,
universal_newlines=True)
except subprocess.CalledProcessError as exc:
std="Status : FAIL", exc.returncode, exc.output
else:
# std="Output: \n{}\n".format(output)
std="compiled sucess"
context={
'msg':'we got data',
'code':code,
'len':len1,
'std':std
}
return Response(context)
This is my view.py file.
response on local server
"msg": "we got data",
"code": "public class Main{\n public static void main(String[]args){\n \n System.out.println(\"HELLO Sid\");\n \n }\n}",
"len": "java",
"std": "compiled sucess"
}
response on heroku server
"msg": "we got data",
"code": "public class Main{\n public static void main(String[]args){\n \n System.out.println(\"HELLO Sid\");\n }\n}",
"len": "java",
"std": [
"Status : FAIL",
127,
"/bin/sh: 1: javac: not found\n"
]
}```