Save gcc compile status to a text file for Java -


I am making an assessment program through Java, which has a bunch of programming questions for C, and this Gives the user the answer to the input as C code, and then press the "Compile" button, which is attached to backlink file which runs user input code via GCC.

I have input and compile is working, but I need to get the output from the compiler and get the text to print the text in the program. I can get a simple "Hello world" collection, but I'm having trouble in programs that require user input with scans, for example, to be printed

  else if (e.getSource (.) Equal (compiled)) {if (question number number 1) {JOptionPane.showMessageDialog (programmable, "Please start evaluation", "compile error", JOptionPane.ERROR_MESSAGE); } Other {FileOutputStream fileWrite; {FileWrite = Try New FileOutputStream ("demo / demo.c"); New printstream (filewitch) .printline (input.gettext ()); // Saves that the user has entered the source file file. Write.close (); @SuppressWarnings ("unused") process process = runtime.gettime (). Exec ("cmd / c compile.bat"); // runs the batch file to compile the source file compilation; {FileStream = Try New FileInputStream ("demo / output.txt"); Inputstream = new data input stream (file stream); Buffer reed = new buffed reader (new inputstream reader (inputstream)); While ((stringline = buffer read.readline ())! = Null (compiled) Append (string line); Compiled.append ("\ n"); } Inputstream.close (); } Hold (IOException exc) {System.err.println ("Unable to read file"); System.exit (-1); }} Hold (IOException exc) {JOptionPane.showMessageDialog (programmable, "demo file not found", "file error", joptionpan. ARROOM_MSES); }}  

This is the functional method for the "compile" button, compileCode () is JFrame which displays the output and textaria for the "compiled" output.

My batch file is:

  c: cd dev-cpp \ bin gcc.exe H: \ workspace \ question program \ demo \ demo.c -o demo & gt ; H: \ Workspace \ Questions Program \ Demo \ compilestatus.txt Demo & gt; H: \ workspace \ questionprogram \ demo \ output.txt  

I'm not sure how I can do this, so code is designed for output if code is required. As a prompt, the user input does not open "start" without adding .exec (), but then the frame appears before the program finishes.

In addition, how can I get the output compiler if the compilation fails due to an error? The way I got it in my batch file, it does not put anything in a text file, if it fails.

The compiler probably writes error messages stderr instead of stdout. Since you are not redirecting stderr, you are clearly not seeing anything in the file. & gt; 2 & gt; Instead of By using you can redirect stderr (which is a contained 1> which is )

If the program requires user input and should not do so that you essentially redirect NUL to the program call (do not inevitably provide input):

  Demo & lt; Nool & gt; Output.txt  

Given that you want some control clearly that what is executed, I suggest that you should not use a batch file. Instead, you can launch individual processes (compiler and program itself) through Java, directly capturing your respective output. Going through the files here is actually unnecessary. You can read the program directly from stdin using

  gcc -xc -o demo -  

can do.


Comments