Okay, so I've been working on this a while (and I've gone through multiple questions to get this far in the project).
Here's the C# code I'm using:
Process p = new Process();
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "javac";
Directory.CreateDirectory(Path.Combine(Application.StartupPath + @"\TempJavaalfgwaepfgawe"));
p.StartInfo.Arguments = "-d " + Path.Combine(Application.StartupPath + @"\TempJavaalfgw开发者_如何转开发aepfgawe") + " " + files;
p.Start();
p.WaitForExit();
MessageBox.Show(p.StandardError.ReadToEnd());
In essence, I am trying to invoke the Java compiler (javac) from a C# application.
Now, when I do this, it wasn't compiling the java code correctly, so I inserted the RedirectStandardError and UseShellExecute as well as the WaitForExit and MessageBox at the end to see the error that was occurring.
Anyways, the error is as follows:
javac: invalid flag: 2010\Projects\Java
Usage: javac [options] [source files]
use -help for a list of possible options
So, what's wrong with my code?
To me, the error looks like part of the location of one of the file paths.
I suggested the fix in the comments, but I also wanted to add a formal answer for others with this problem.
When you pass in arguments to a process, strings that have spaces need to be quoted. This tells the argument parser that you really mean one argument. (different arguments are usually divided by white space)
精彩评论