Collabedit Java compiler and runner

I have an interview tonight, where I am told that I am supposed to do Java coding on a shared document via the platform.
As I am checked on both speed and correctness I figured that it would be nice to know when I did obvious syntax errors, but as far as I can see, collabedit supports syntax highlighting but does not support any error detecting or running of the actual program.
But it is possible to download your shared document, with the click of a mouse.
This is why I have just hacked together a small python script that listens for a file to be downloaded, and then runs the javac and java tools on it.
I call the script, and it is created to be used on a linux environment, you might be able to use it on other platforms by fx changing the os.system("clear") to os.system("cls") or likewise.

If you have any suggestions, feel free to comment.

# Author: Kraen Hansen (
# Date: November 2011
import sys
import os.path
from time import sleep
def compile_java(filename, classname, autorun):
	print "Compiling "+filename
	result = os.system("javac "+filename)
	if result == 0:
		print "Compiled successfully!"
		should_run = autorun
		if not should_run:
			run = raw_input("Would you like to run it? [Y/n]")
			if(run != "n" and run != "N"):
				should_run = True
		if should_run:
			folder = os.path.split(filename)[0]
			runcommand = "java -cp ""+folder+"" "+classname
			print "Running the program! ("+runcommand+")"
			print "------------------------------"
			print ""
			result = os.system(runcommand)
			print ""
			print "------------------------------"
			print "Program terminated with the signal:", result
			raw_input("Press any key to continue.")
		raw_input("Press any key to continue.")
def collabedit_java_compiler(filename, classname, autorun):
	running = True
			print "Found the source file!"
			compile_java(filename, classname, autorun)
			print "Removing the file ..."
			print "Didn't find a file ... waiting 1 sec"
if __name__ == "__main__":
	print "Started the collabedit java compiler."
	if len(sys.argv) == 3:
		filename = sys.argv[1]
		classname = sys.argv[2]
		collabedit_java_compiler(filename, classname, True)
		print """Usage: "path to downloaded file" "Main java class":"""
		print """Example: ./ /home/creen/Downloads/ Test"""

One Reply to “Collabedit Java compiler and runner”

  1. Hey thanks, I have an interview too and was just about to write my own, figured i do a search for one first. Goodluck.

Leave a Reply

Your email address will not be published.