ProcessBuilder in Java to create a basic online Judge - GeeksforGeeks
We have discussed Process and Runtime to create an external process. In this post, ProcessBuilder is discussed which serves the same purpose.
Let us understand an application where we need to get source code and find out the language. The application needs a string (containing source code) as input. The application needs to find out the language in which source code in written. Source codes will be having a relevant extension. For example –
- Code in C language will have ".c" extension
- Code in C++ will have ".cpp" extension
- Code in Java will have ".java" extension
- Code in Python will have ".py" extension
Using the name of input file the required language, to be used, can be found out.
Recall that compiling a code in java is done with command –
"javac Main.java"
and to execute it we use –
"java Main"
Similar commands are there for other languages. Therefore we need a separate text file containing all the commands which our software should execute one by one.
In case of error (Runtime or Compiler Errors) our application should write the error logs in a separate text file. Whatever output the source code is producing, our application should write it in another text file.
We use "ProcessBuilder" class in "Language" package which can execute OS processes.
Read full article from ProcessBuilder in Java to create a basic online Judge - GeeksforGeeks
No comments:
Post a Comment