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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
public static void main(String[] args) throws IOException, InterruptedException {
//System.out.println((System.getProperties()+"").replace(",", ",\n"));
test1(args);
}
public static void test1(String[] args) throws IOException, InterruptedException{
//String ttyConfig = stty("-g");
// set the console to be character-buffered instead of line-buffered
//stty("-icanon min 1");
// disable character echoing
//stty("-echo");
//System.setIn(new FileInputStream(FileDescriptor.in));
String[] exeCmd = new String[3];
exeCmd[0] = "/bin/sh";
exeCmd[1] = "-c";
String argsAll = "";
for (int i = 0; i < args.length; i++) {
//exeCmd[i+2] = args[i];
argsAll += args[i];
}
//argsAll.replace("\"", """)
exeCmd[2] = "\""+argsAll+"\"";
try {
final Process process = Runtime.getRuntime().exec(exeCmd);
final InputStream is = process.getInputStream();
final InputStream es = process.getErrorStream();
new Thread() {
public void run() {
try {
byte[] buffer = new byte[1024];
for (int count = 0; (count = is.read(buffer)) >= 0;) {
System.out.write(buffer, 0, count);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
new Thread() {
public void run() {
try {
byte[] buffer = new byte[1024];
for (int count = 0; (count = es.read(buffer)) >= 0;) {
System.err.write(buffer, 0, count);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
int returnCode = process.waitFor();
System.out.println("Return code = " + returnCode);
} catch (Exception e) {
e.printStackTrace();
}
//stty(ttyConfig);
Thread.sleep(5000);
System.exit(0);
} |
Partager