Quote:
Originally Posted by KyleUbenk
Hello, I am attempting to compile java code from within my program. Basically I have a file in the directory with Java source code, and I want to be able to compile it from within my program. The only solution I have found so far is running the javac process :
Process.Start("javac source.java); But this doesn't seem to work (File not found).
And i would also like to get the output after compiling to a string (Error messages etc). Any other suggestions? Help is much appreciated.
Edit : Worked out now using Process.Start("javac","Leecher.java");
Only problem is now how would i get the output of that to a string?
Try using StartInfo and RedirectStandardOutput set to true. Something like (N.B This has not been tested)
- public static String compileJava (String file) {
-
Process p = new Process();
-
p.StartInfo.FileName = "javac.exe";
-
p.StartInfo.Arguments = file;
-
p.StartInfo.UseShellExecute = false;
-
p.StartInfo.RedirectStandardOutput = true;
-
p.Start();
-
String output = p.StandardOutput.ReadToEnd();
-
Console.WriteLine(output);
-
return output;
-
}