0

I am creating java compiler in c# .it is working perfect if there is no input.but it ask forstrong text input it give me error (Exception in thread "main" java.util.NoSuchElementException: No line found)

public void executeit()
{
 adresss = "";
 string dir = textBox1.Text;
 adresss = dir;
 ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
 info.CreateNoWindow = true;
 string[] s = new string[30];
 s = Directory.GetDirectories(@"C:\Program Files\Java\", "jdk1*");
 info.WorkingDirectory = s[0] + @"\bin\";
 info.Arguments = "/c javac " + "\"" + dir + "\"";
 Process p = new Process();
 info.UseShellExecute = false;
 info.RedirectStandardError = true;
 info.RedirectStandardOutput = true;
 label1.Text = "";

 p.StartInfo = info;
 p.Start();

 StreamReader sw = p.StandardError;
 string err = sw.ReadToEnd();

 label1.Text = err;
 if (label1.Text == "")
 {
  label1.Text = "Compiled without Errors";
 }

}

and it is java file:

import java.util.Scanner;
public class inputtry {
    public static void main (String args[]){
        Scanner reader = new Scanner(System.in);
        System.out.println("Enter the first number");
        //get user input for a
        String a=reader.nextLine();
        System.out.print("number is:");
         System.out.print(a);
    }
}
dovid
  • 6,354
  • 3
  • 33
  • 73
waqasanwaar
  • 23
  • 1
  • 5
  • Why are you calling javac through cmd instead of running it alone? – PTwr Jan 12 '14 at 14:40
  • it executes .class file..how can I run it alone – waqasanwaar Jan 12 '14 at 14:53
  • Run it alone as in: new ProcessStartInfo("path\\javac.exe"); – PTwr Jan 12 '14 at 14:55
  • will it work for input ? – waqasanwaar Jan 12 '14 at 14:59
  • I see no reason why it should not work, as it stands now, you are just calling program that will call targeted one, thus creating unnecessary element in chain. Another thing is that you might need to handle StandardInput from your code. – PTwr Jan 12 '14 at 15:04
  • thanks @PTwr ..i did it like this info.UseShellExecute = false; info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.RedirectStandardInput = true; p.StartInfo = info; p.Start(); textBox2.Text = ""; StreamReader sw = p.StandardError; StreamReader sr = p.StandardOutput; StreamWriter stwr = p.StandardInput; string err = sw.ReadToEnd(); but now deadlock occur .. – waqasanwaar Jan 12 '14 at 16:21
  • Check answer [here](http://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why). – PTwr Jan 12 '14 at 17:07

0 Answers0