Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39558
1
#!/usr/bin/python
2
3
# java2html.py - used by java edit mode
4
5
import os, sys, subprocess, errno, re
6
7
def java2html(path):
8
if not os.path.exists(path):
9
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), path)
10
11
(root, ext) = os.path.splitext(path)
12
if ext.lower() != ".java":
13
raise ValueError('Java input file required, got {}'.format(path))
14
15
with open(path, 'r') as f:
16
s = f.read()
17
try:
18
(path, file) = os.path.split(path)
19
(child_stdin, child_stdout, child_stderr) = os.popen3('cd "%s"; javac "%s"; java "%s"' % (path, file, file[:-5]))
20
output = child_stderr.read()
21
output += '\n' + child_stdout.read()
22
sys.stdout.flush()
23
sys.stderr.flush()
24
print(output.replace('\n', '<br/>'))
25
finally:
26
pass
27
28
def main():
29
if len(sys.argv) != 2:
30
raise ValueError('Usage: {} path/to/file.java'.format(sys.argv[0]))
31
32
java2html(sys.argv[1])
33
34
if __name__ == "__main__":
35
main()
36
37
38
39
40