在c#中执行multi-line cmd命令

时间:2014-01-12 14:34:08

标签: c# cmd

我在c#中创建java编译器。如果没有输入,它正在工作完美。但是它要求forstrong文本输入它给我错误(线程中的异常“main”java.util.NoSuchElementException:找不到行)

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";
 }

}

它是java文件:

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);
    }
}

0 个答案:

没有答案