-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompileRunJavaProgram.java
More file actions
57 lines (42 loc) · 1.68 KB
/
Copy pathCompileRunJavaProgram.java
File metadata and controls
57 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.*;
public class CompileRunJavaProgram {
public static void main(String[] args) {
try {
System.out.println("**********");
CompileRunJavaProgram.runProcess("javac /home/yatin/bla/demo.java");
System.out.println("**********");
CompileRunJavaProgram.runProcess("java -cp /home/yatin/bla demo");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void printLines(String cmd, InputStream ins,OutputStream outputStream) throws Exception {
String line = null;
BufferedReader in = new BufferedReader(
new InputStreamReader(ins));
while ((line = in.readLine()) != null) {
//outputStream.write(ins.read());
System.out.println(cmd + " ----- " + line);
}
}
public static void runProcess(String command) throws Exception {
Process pro = Runtime.getRuntime().exec(command);
printLines(command + " stdout:", pro.getInputStream(), pro.getOutputStream());
printLines(command + " stderr:", pro.getErrorStream(), pro.getOutputStream());
pro.waitFor();
System.out.println(command + " exitValue() " + pro.exitValue());
}
}
class demo1 {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = in.nextLine();
System.out.println("Name is: " + name);
in.close();
}
}