Rofael Behnam
Rofael Behnam

Reputation: 39

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?

Upvotes: 0

Views: 1147

Answers (4)

Avner Shahar-Kashtan
Avner Shahar-Kashtan

Reputation: 14700

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.

Upvotes: 0

Shai
Shai

Reputation: 25595

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.

Upvotes: 0

Davide Piras
Davide Piras

Reputation: 44605

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.

Upvotes: 0

Oded
Oded

Reputation: 499132

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

Upvotes: 3

Related Questions