-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExec.java
More file actions
26 lines (25 loc) · 734 Bytes
/
Copy pathExec.java
File metadata and controls
26 lines (25 loc) · 734 Bytes
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
import java.io.InputStream;
import java.io.IOException;
public class Exec{
public static void main(String[] args) {
if(args.length != 1){
System.err.println("usage: java Exec program");
return;
}
try{
Process p = Runtime.getRuntime().exec(args[0]);
// Obtaining standard output of process that p represented.
InputStream is = p.getInputStream();
int _byte;
while((_byte = is.read())!=-1){
System.out.print((char)_byte);
}
// Wait for the executing process's exit status.
System.out.println("\nExit status: " + p.waitFor());
}catch(InterruptedException ie){
assert false;
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}