@@ -237,14 +237,17 @@ def input_file_to_string(path, num_cases):
237237 return inputs
238238
239239 @staticmethod
240- def cleanup (num_cases ):
240+ def cleanup (num_cases , basename , extension ):
241241 """
242242 Method to clean up temporarily created files
243243 """
244244 for i in xrange (num_cases ):
245245 if os .path .isfile ('temp_output' + str (i )):
246246 os .remove ('temp_output' + str (i ))
247247
248+ if extension == 'java' :
249+ os .system ('rm ' + basename + '*.class' )
250+
248251 @staticmethod
249252 def handle_kbd_interrupt (site , contest , problem ):
250253 """
@@ -276,6 +279,7 @@ def run_solution(args):
276279
277280 extension = problem .split ('.' )[- 1 ]
278281 problem = problem .split ('.' )[0 ]
282+ basename = problem .split ('/' )[- 1 ]
279283 problem_path = os .path .join (os .getcwd (), problem )
280284
281285 if not os .path .isfile (problem_path + '.' + extension ):
@@ -296,7 +300,7 @@ def run_solution(args):
296300
297301 for i in xrange (num_cases ):
298302 status = os .system ('cat ' + os .path .join (testcases_path , 'Input' + str (
299- i )) + ' | timeout 3s python ' + problem + '.py > temp_output' + str (i ))
303+ i )) + ' | timeout 3s python \' ' + problem_path + '.py\' > temp_output' + str (i ))
300304 if status == 124 :
301305 # Time Limit Exceeded
302306 results += [Utilities .colors ['BOLD' ] +
@@ -330,17 +334,18 @@ def run_solution(args):
330334 results += [Utilities .colors ['BOLD' ] +
331335 Utilities .colors ['RED' ] + 'RTE' + Utilities .colors ['ENDC' ]]
332336
333- elif extension == ' cpp' or extension == 'c' :
337+ elif extension in [ 'c' , ' cpp', 'java' ] :
334338
335- compiler = {'c' : 'gcc' , 'cpp' : 'g++' }[extension ]
339+ compiler = {'c' : 'gcc' , 'cpp' : 'g++' , 'java' : 'javac -d .' }[extension ]
340+ execute_command = {'c' : './a.out' , 'cpp' : './a.out' , 'java' : 'java ' + basename }[extension ]
336341 compile_status = os .system (
337- compiler + ' ' + problem_path + '.cpp ' )
342+ compiler + ' \' ' + problem_path + '.' + extension + ' \' ' )
338343
339344 if compile_status == 0 :
340345
341346 # Compiled successfully
342347 for i in xrange (num_cases ):
343- status = os .system ('timeout 2s ./a.out < ' + os .path .join (
348+ status = os .system ('timeout 2s ' + execute_command + ' < ' + os .path .join (
344349 testcases_path , 'Input' + str (i )) + ' > temp_output' + str (i ))
345350 if status == 124 :
346351 # Time Limit Exceeded
@@ -382,7 +387,7 @@ def run_solution(args):
382387 sys .exit (0 )
383388
384389 else :
385- print 'Supports only C, C++ and Python as of now. Support for Java coming soon .'
390+ print 'Supports only C, C++, Python and Java as of now.'
386391 sys .exit (0 )
387392
388393 from terminaltables import AsciiTable
@@ -409,7 +414,7 @@ def run_solution(args):
409414 print table .table
410415
411416 # Clean up temporary files
412- Utilities .cleanup (num_cases )
417+ Utilities .cleanup (num_cases , basename , extension )
413418
414419 else :
415420 print 'Test cases not found locally...'
0 commit comments