简体   繁体   中英

Java Compiler ASP.NET

I'm trying to make an online compiler for java using ASP.NET C#

Process p=new Process();
p.StartInfo.FileName = "C:\\Program files\\Java\\bin\\javac.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = "C:\\Hello.java";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardOutput.ReadToEnd();
p.WaitForExit();

I run javac.exe to compile Hello.java, but the process isn't allowed by ASP.NET to write Hello.class to disk

But on doing it manually through cmd.exe without using ASP.NET or progmatically using C# only it runs perfectly

Can you help me make an online java compiler using ASP.NET or PHP for compiling Algorithmic assignments?

This is a permissions problem - you have two options:

  • Change the application pool identity to an account that has write permissions
  • Give write permissions to the current application pool identity account

you should configure the access rights for the ASPNET user, this changes a bit depending on which version of IIS and Windows Server the web application runs.

Consider to store the output data locally on the server's disk on a proper location, not directly C or any system folder. let's say C:\\JavaOutput\\ then give read/write permissions to the ASPNET user to that folder.

This is a permission problem. You need to allow full permissions to c:\\ for the ASP.NET USER\\IISUSER. That's obviously a WRONG approach.

Your working directory should be the directory in which your web application sits.

Where on the disk does the compiler try to store Hello.class? Chances are, it's in a folder where the ASP.NET process has no permissions to write.

Some tips:

1) Find out what permissions the ASP.NET worker process has. If using IIS, check out the identity of the ApplicationPool it's running under. Chances are it's running under a limited profile.

2) Find a folder where the ASP.NET worker process can write to. This should probably be in a directory under the application root (~), or in some TEMP folder.

3) Check if the javac command-line allows you to specify an explicit output directory. If not, use p.StartInfo.WorkingDirectory to specify a working folder for the process, which will probably make javac output to the specified folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM